Skip to content

GateDigger/GDPrefixTree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GDPrefixTree

is GateDigger's generic implementation of a prefix tree.

Overview

Core

The core part of the project is split up into subfolders in order to be as modular as possible.

  • Core/Base - neccessary functionality
    • Provides GDPrefixTree<S, T> functionality
      • Get
      • Set
      • Static traversal methods
    • Requires
      • Implementation of IGDKey<S>
      • Implementation of IGDNode<S, T>
        • IsPathing
        • Value
        • AppendChildNode
        • FindChildNode
  • Core/Update - "smart" updates of values
    • Provides GDPrefixTree<S, T> functionality
      • Update
      • SetOrUpdate
    • Requires
      • Core/Base requirements
  • Core/Removal - value deletion
    • Provides GDPrefixTree<S, T> functionality
      • Remove
      • RemoveBranch
    • Requires
      • Core/Base requirements
      • Additional implementation of IGDNode<S, T>
        • RemoveChildNode
  • Core/Enumeration - systematic enumeration of nodes
    • Provides
      • GDPrefixTree<S, T> implementation of IEnumerable<IGDNode<S, T>>
      • Extension of IGDNode<S, T> by IEnumerable<IGDNode<S, T>>
    • Requires
      • IGDNode<S, T> implementation
        • Including IEnumerable<IGDNode<S, T>>
  • Core/Enumeration/GetEnumerator - absorbtion of interface IGDNode<S, T> into abstract class GDNode<S, T>
    • Provides
      • Implementation of IEnumerable<IGDNode<S, T>> extension of IGDNode<S, T>
    • Requires
      • Implementation of GDNode<S, T>, equivalent to base IGDNode<S, T>
        • Including GetChildNodes

The example

Example_WordCounting contains an implementations of IGDKey<char> and GDNode<char, int> suited for word counting. Program.cs contains a script which reads through a text file and builds a prefix tree which counts word occurences. User can query the tree.

IGDKey<T> vs IEnumerable<T>/IEnumerator<T>

I decided to not use IEnumerablerator because it disallows composition of traversal methods. A class implementation of IGDKey<T> lets the developer invoke a read-only-traversal of the tree, do work on the leaf node and call a read-write-traversal from where read-only stopped, without any redundant work. If anyone manages to make IEnumerator do this without exception catching, please tell me, I'd love to see that.

License

MIT License

Copyright (c) 2023 GateDigger

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Releases

No releases published

Packages

No packages published

Languages