Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

Summary

This pull request implements a comprehensive solution for issue #132 by introducing a tree-like representation for links that provides a more hierarchical and flexible approach compared to the traditional flat IList<TLinkAddress> structure.

Key Changes

  • ILinkTree Interface: Added ILinkTree<TLinkAddress> interface with tree-like navigation methods
  • LinkTree Implementation: Implemented LinkTree<TLinkAddress> struct with full tree functionality
  • Enhanced Link Struct: Updated Link<TLinkAddress> struct to implement ILinkTree interface
  • Tree-Compatible Extensions: Added tree-compatible extension methods in ILinksExtensions
  • Backward Compatibility: Maintained full backward compatibility with existing IList-based APIs
  • Conversion Methods: Provided conversion methods between tree and list representations

Features

  • Hierarchical Representation: Tree-like structure with parent/child relationships
  • Tree Navigation: Methods like GetChild, GetSourceAsTree, GetTargetAsTree
  • Seamless Conversion: Implicit conversions between Link, LinkTree, and arrays
  • Extended API: New extension methods (SingleOrDefaultTree, AllTrees, FormatTree, etc.)
  • Flexible Structure: Support for both flat and hierarchical link structures

Architecture

// New tree interface
public interface ILinkTree<TLinkAddress>
{
    TLinkAddress Index { get; }
    TLinkAddress Source { get; }
    TLinkAddress Target { get; }
    ILinkTree<TLinkAddress>? Parent { get; }
    IEnumerable<ILinkTree<TLinkAddress>> Children { get; }
    // ... navigation and utility methods
}

// Enhanced Link struct now implements both IList and ILinkTree
public struct Link<TLinkAddress> : IEquatable<Link<TLinkAddress>>, 
                                   IReadOnlyList<TLinkAddress>, 
                                   IList<TLinkAddress>, 
                                   ILinkTree<TLinkAddress>
{
    // ... existing functionality plus tree interface implementation
}

Usage Examples

// Traditional approach still works
var link = new Link<ulong>(1, 2, 3);
var array = link.ToArray(); // [1, 2, 3]

// New tree-like approach
ILinkTree<ulong> tree = link;
var index = tree.Index;     // 1
var source = tree.Source;   // 2
var target = tree.Target;   // 3

// Extension methods for tree operations
var result = links.SingleOrDefaultTree(query);
var all = links.AllTrees(restriction);
var formatted = links.FormatTree(tree);

Backward Compatibility

All existing code continues to work without modification:

  • IList<TLinkAddress> methods still function as before
  • Implicit conversions handle seamless interoperability
  • No breaking changes to existing APIs

Testing

  • All existing tests pass (21/21 successful)
  • Added demonstration script in /experiments/TreeStructureDemo.cs
  • Comprehensive compilation with no errors (warnings only)

Test Plan

  • Existing test suite passes completely
  • Project builds without errors
  • Tree interface methods work correctly
  • Backward compatibility maintained
  • Extension methods function as expected
  • Conversion methods work bidirectionally

🤖 Generated with Claude Code


Resolves #132

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #132
@konard konard self-assigned this Sep 14, 2025
…nkAddress>

This implements a comprehensive solution for issue #132 by introducing a
tree-like representation for links that provides a more hierarchical and
flexible approach compared to the traditional flat IList<TLinkAddress> structure.

Key changes:
- Added ILinkTree<TLinkAddress> interface with tree-like navigation methods
- Implemented LinkTree<TLinkAddress> struct with full tree functionality
- Enhanced Link<TLinkAddress> struct to implement ILinkTree interface
- Added tree-compatible extension methods in ILinksExtensions
- Maintained full backward compatibility with existing IList-based APIs
- Provided conversion methods between tree and list representations

Features:
- Hierarchical link representation with parent/child relationships
- Tree navigation methods (GetChild, GetSourceAsTree, GetTargetAsTree)
- Backward compatibility through implicit conversions
- Extension methods for tree-specific operations (SingleOrDefaultTree, AllTrees, etc.)
- Support for both flat and hierarchical link structures

The implementation enables more natural representation of complex link
relationships while preserving all existing functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Instead of IList<TLink> use the tree like in the links notation Implement tree-like structure for links notation instead of IList<TLinkAddress> Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Instead of IList<TLink> use the tree like in the links notation

2 participants