https://github.com/open-net-libraries/open.hierarchy
Interfaces and classes helful in managing tree-like data structures.
https://github.com/open-net-libraries/open.hierarchy
Last synced: 6 days ago
JSON representation
Interfaces and classes helful in managing tree-like data structures.
- Host: GitHub
- URL: https://github.com/open-net-libraries/open.hierarchy
- Owner: Open-NET-Libraries
- License: mit
- Created: 2017-10-27T21:41:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-17T00:35:05.000Z (7 months ago)
- Last Synced: 2025-05-14T02:22:45.691Z (about 1 month ago)
- Language: C#
- Size: 117 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Open.Hierarchy
[](https://www.nuget.org/packages/Open.Hierarchy/)
## Introduction
Open.Hierarchy is a versatile library designed for creating and manipulating tree structures with a focus on efficiency and ease of use. With the `Node` class and its supporting components, this library enables users to create tree structures that have a unidirectional parent-to-child relationship, enabling more efficient use of memory and simplified garbage collection.
## `Node`
`Node` is a versatile class that represents a node in a bidirectional tree. It can be used as-is or to act as a bidirectional map of a unidirectional tree. In a bidirectional tree, it is crucial to ensure that a node cannot occur multiple times, although its value can occur any number of times. This approach enables the creation of 'value sub-trees' with duplicate references but not duplicate instances. By using `Node` as a container, a single instance can exist multiple times in a tree but still be uniquely identifiable by its position.
## `Node.Factory`
The `Node.Factory` class provides useful methods for creating, mapping, cloning, and recycling `Node` instances:
### Blank Instance
- `.GetBlankNode()`: Retrieves a blank node from the underlying object pool or creates a new one.
### Mapping
- `.Map(root)`: Generates a node hierarchy map based on whether the root or any of its children implement the `IParent` interface.
### Cloning
- `.Clone(node)`: Creates a copy of the node map.
### Recycling
- `Factory.Recycle(node)`: Recycles a `Node` instance by tearing down the node itself and its children, returning them to an object pool.
**WARNING:** The `Factory.Recycle(node)` method is a potential source of issues if multiple references are retained. It must be used with care to avoid unexpected behavior.