Beispiel #1
0
 /// <summary>Constructs a new trie that uses linked hash tables of linked lists.</summary>
 /// <param name="equate">The equality delegate for the keys.</param>
 /// <param name="hash">The hashing function for the keys.</param>
 public TrieLinkedHashLinked(Equate <T> equate = null, Hash <T> hash = null)
 {
     _count = 0;
     _map   = new MapHashLinked <Node, T>(
         equate ?? Towel.Equate.Default,
         hash ?? Towel.Hash.Default);
 }
Beispiel #2
0
 /// <summary>This constructor is for cloning purposes.</summary>
 /// <param name="set">The set to clone.</param>
 /// <runtime>O(n)</runtime>
 internal SetHashLinked(SetHashLinked <T> set)
 {
     _equate = set._equate;
     _hash   = set._hash;
     _table  = (Node[])set._table.Clone();
     _count  = set._count;
 }
Beispiel #3
0
 private MapHashLinked(MapHashLinked <T, K> setHashList)
 {
     _equate = setHashList._equate;
     _hash   = setHashList._hash;
     _table  = setHashList._table.Clone() as Node[];
     _count  = setHashList._count;
 }
Beispiel #4
0
 private Set(Set <STRUCTURE, T> set_generic)
 {
     this._equate = set_generic._equate;
     this._hash   = set_generic._hash;
     this._table  = set_generic._table.Clone() as STRUCTURE[];
     this._count  = set_generic._count;
 }
Beispiel #5
0
 /// <summary>This constructor is for cloning purposes.</summary>
 /// <param name="map">The map to clone.</param>
 /// <runtime>O(n)</runtime>
 internal MapHashLinked(MapHashLinked <T, K> map)
 {
     _equate = map._equate;
     _hash   = map._hash;
     _table  = (Node[])map._table.Clone();
     _count  = map._count;
 }
Beispiel #6
0
 private SetHashList(SetHashList <T> setHashList)
 {
     this._equate = setHashList._equate;
     this._hash   = setHashList._hash;
     this._table  = setHashList._table.Clone() as Node[];
     this._count  = setHashList._count;
 }
Beispiel #7
0
 public TreeMap(T head, Equate <T> equate, Hash <T> hash)
 {
     this._equate = equate;
     this._hash   = hash;
     this._head   = head;
     this._tree   = new MapHashLinked <NodeData, T>(this._equate, this._hash);
     this._tree.Add(this._head, new NodeData(default(T), new SetHashList <T>(this._equate, this._hash)));
 }
Beispiel #8
0
 public GraphSetOmnitree(Equate <T> equate, Compare <T> compare, Hash <T> hash, T min, T max, Omnitree.Average <T> average)
 {
     this._nodes = new SetHashList <T>(equate, hash);
     Omnitree.Locate <Edge, T> locationFunction = (Edge a) => { return(Accessor.Get(new T[] { a.Start, a.End })); };
     this._edges = new OmnitreeLinked <Edge, T>(
         new T[] { min, min },
         new T[] { max, max },
         locationFunction, compare, average);
 }
Beispiel #9
0
        public override bool Equals(object obj)
        {
            if (!(obj is Equate))
            {
                return(base.Equals(obj));
            }
            Equate label2 = obj as Equate;

            return(Location.Offset == label2.Location.Offset && LabelName == label2.LabelName);
        }
Beispiel #10
0
 private SetHashArray(SetHashArray <T> setHashArray)
 {
     this._equate    = setHashArray._equate;
     this._hash      = setHashArray._hash;
     this._table     = setHashArray._table.Clone() as int[];
     this._nodes     = setHashArray._nodes.Clone() as Node[];
     this._count     = setHashArray._count;
     this._lastIndex = setHashArray._lastIndex;
     this._freeList  = setHashArray._freeList;
 }
Beispiel #11
0
 internal AddableArray(AddableArray <T> listArray)
 {
     this._list = new T[listArray._list.Length];
     for (int i = 0; i < this._list.Length; i++)
     {
         this._list[i] = listArray._list[i];
     }
     this._equate = listArray._equate;
     this._count  = listArray._count;
 }
Beispiel #12
0
 /// <summary>Creates an instance of a ListArray, and sets it's minimum capacity.</summary>
 /// <param name="expectedCount">The initial and smallest array size allowed by this list.</param>
 /// <remarks>Runtime: O(1).</remarks>
 public AddableArray(int expectedCount, Equate <T> equate)
 {
     if (expectedCount < 1)
     {
         throw new System.ArgumentOutOfRangeException("expectedCount", "expectedCount must be greater than 0");
     }
     this._equate = equate;
     _list        = new T[expectedCount];
     _count       = 0;
 }
Beispiel #13
0
#pragma warning disable CS1587
        /// <summary>Constructs a new MapHashArray using the default Equate and Hash functions.</summary>
        /// <param name="expectedCount">The expected count to initialize the size of the data structure to allow for.</param>
        //public MapHashArray(int expectedCount) : this(Towel.Equate.Default, Towel.Hash.Default) { }
#pragma warning restore CS1587

        /// <summary>Constructs a new hash table instance.</summary>
        /// <runtime>O(1)</runtime>
        public MapHashArray(Equate <K> equate = null, Hash <K> hash = null)
        {
            _nodes     = new Node[Towel.Hash.TableSizes[0]];
            _table     = new int[Towel.Hash.TableSizes[0]];
            _equate    = equate ?? Towel.Equate.Default;
            _hash      = hash ?? Towel.Hash.Default;
            _lastIndex = 0;
            _count     = 0;
            _freeList  = -1;
        }
Beispiel #14
0
 public TreeMap(T head, Equate <T> equate, Hash <T> hash)
 {
     _equate = equate;
     _hash   = hash;
     _head   = head;
     _tree   = new MapHashLinked <Node, T>(_equate, _hash)
     {
         { _head, new Node(default(T), new SetHashLinked <T>(_equate, _hash)) }
     };
 }
Beispiel #15
0
#pragma warning disable CS1587
        /// <summary>Constructs a new MapHashArray using the default Equate and Hash functions.</summary>
        /// <param name="expectedCount">The expected count to initialize the size of the data structure to allow for.</param>
        //public MapHashArray(int expectedCount) : this(Towel.Equate.Default, Towel.Hash.Default) { }
#pragma warning restore CS1587

        /// <summary>Constructs a new hash table instance.</summary>
        /// <runtime>O(1)</runtime>
        public MapHashArray(Equate <K> equate, Hash <K> hash)
        {
            this._nodes     = new Node[Towel.Hash.TableSizes[0]];
            this._table     = new int[Towel.Hash.TableSizes[0]];
            this._equate    = equate;
            this._hash      = hash;
            this._lastIndex = 0;
            this._count     = 0;
            this._freeList  = -1;
        }
Beispiel #16
0
 internal ListArray(ListArray <T> listArray)
 {
     _list = new T[listArray._list.Length];
     for (int i = 0; i < _list.Length; i++)
     {
         _list[i] = listArray._list[i];
     }
     _equate = listArray._equate;
     _count  = listArray._count;
 }
Beispiel #17
0
 /// <summary>Creates an instance of a ListArray, and sets it's minimum capacity.</summary>
 /// <param name="expectedCount">The initial and smallest array size allowed by this list.</param>
 /// <param name="equate">The equate delegate to be used by the list.</param>
 /// <runtime>O(1)</runtime>
 public ListArray(int expectedCount, Equate <T> equate)
 {
     if (expectedCount < 1)
     {
         throw new ArgumentOutOfRangeException(nameof(expectedCount), expectedCount, "!(0 < " + nameof(expectedCount) + ")");
     }
     _equate = equate;
     _list   = new T[expectedCount];
     _count  = 0;
 }
Beispiel #18
0
 /// <summary>Constructs a new hash table instance.</summary>
 /// <remarks>Runtime: O(1).</remarks>
 public SetHashArray(Equate <T> equate, Hash <T> hash)
 {
     this._nodes     = new Node[Seven.Hash.TableSizes[0]];
     this._table     = new int[Seven.Hash.TableSizes[0]];
     this._equate    = equate;
     this._hash      = hash;
     this._lastIndex = 0;
     this._count     = 0;
     this._freeList  = -1;
 }
Beispiel #19
0
 /// <summary>Constructs a new GraphSetOmnitree.</summary>
 /// <param name="equate">The equate delegate for the data structure to use.</param>
 /// <param name="compare">The compare delegate for the data structure to use.</param>
 /// <param name="hash">The hash delegate for the datastructure to use.</param>
 public GraphSetOmnitree(Equate <T> equate, Compare <T> compare, Hash <T> hash)
 {
     _nodes = new SetHashLinked <T>(equate, hash);
     _edges = new OmnitreePointsLinked <Edge, T, T>(
         (Edge a, out T start, out T end) =>
     {
         start = a.Start;
         end   = a.End;
     },
         compare, compare);
 }
Beispiel #20
0
 /// <summary>This constructor is for cloning purposes.</summary>
 /// <param name="set">The set to clone.</param>
 /// <param name="clone">A delegate for cloning the structures.</param>
 /// <runtime>O(n)</runtime>
 internal Set(Set <Structure, T> set, StructureClone clone)
 {
     _factory = set._factory;
     _equate  = set._equate;
     _hash    = set._hash;
     _table   = new Structure[set._table.Length];
     for (int i = 0; i < _table.Length; i++)
     {
         if (!(set._table[i] is null))
         {
             _table[i] = clone(set._table[i]);
         }
     }
     _count = set._count;
 }
Beispiel #21
0
        /// <summary>Checks to see if a given object is in this data structure.</summary>
        /// <typeparam name="T">The generic type stored in the structure.</typeparam>
        /// <param name="stepper">The structure to check against.</param>
        /// <param name="check">The item to check for.</param>
        /// <param name="equate">Delegate for equating two instances of the same type.</param>
        /// <returns>true if the item is in this structure; false if not.</returns>
        public static bool Contains <T>(this StepperBreak <T> stepper, T check, Equate <T> equate)
        {
            bool contains = false;

            stepper((T step) =>
            {
                if (equate(step, check))
                {
                    contains = true;
                    return(StepStatus.Break);
                }
                return(StepStatus.Continue);
            });
            return(contains);
        }
Beispiel #22
0
        internal ListLinked(ListLinked <T> listLinked)
        {
            Node head          = new Node(listLinked._head.Value);
            Node current       = listLinked._head.Next;
            Node current_clone = head;

            while (current != null)
            {
                current_clone.Next = new Node(current.Value);
                current_clone      = current_clone.Next;
                current            = current.Next;
            }
            _equate = listLinked._equate;
            _head   = head;
            _tail   = current_clone;
            _count  = listLinked._count;
        }
Beispiel #23
0
        /// <summary>Constructs a new GraphSetOmnitree.</summary>
        /// <param name="equate">The equate delegate for the data structure to use.</param>
        /// <param name="compare">The compare delegate for the data structure to use.</param>
        /// <param name="hash">The hash delegate for the datastructure to use.</param>
        public GraphSetOmnitree(
            Equate <T> equate   = null,
            Compare <T> compare = null,
            Hash <T> hash       = null)
        {
            equate  = equate ?? Equate.Default;
            compare = compare ?? Compare.Default;
            hash    = hash ?? Hash.Default;

            _nodes = new SetHashLinked <T>(equate, hash);
            _edges = new OmnitreePointsLinked <Edge, T, T>(
                (Edge a, out T start, out T end) =>
            {
                start = a.Start;
                end   = a.End;
            },
                compare, compare);
        }
Beispiel #24
0
        /// <summary>Trys to look up an item this structure by a given key.</summary>
        /// <typeparam name="T">The generic type stored in the structure.</typeparam>
        /// <typeparam name="K">The type of the key to look up.</typeparam>
        /// <param name="stepper">The structure to check against.</param>
        /// <param name="key">The key to look up.</param>
        /// <param name="equate">Delegate for equating two instances of different types.</param>
        /// <param name="item">The item if it was found or null if not the default(Type) value.</param>
        /// <returns>true if the key was found; false if the key was not found.</returns>
        public static bool TryGet <T, K>(this StepperBreak <T> stepper, K key, Equate <T, K> equate, out T item)
        {
            bool contains = false;
            T    temp     = default(T);

            stepper((T step) =>
            {
                if (equate(step, key))
                {
                    contains = true;
                    temp     = step;
                    return(StepStatus.Break);
                }
                return(StepStatus.Continue);
            });
            item = temp;
            return(contains);
        }
Beispiel #25
0
 /// <summary>Constructs a new hash table instance.</summary>
 /// <remarks>Runtime: O(stepper).</remarks>
 public MapHashLinked(Equate <K> equate, Hash <K> hash, int expectedCount)
 {
     if (expectedCount > 0)
     {
         int prime = (int)(expectedCount * (1 / _maxLoadFactor));
         while (Theta.Mathematics.Compute <int> .IsPrime(prime))
         {
             prime++;
         }
         this._table = new Node[prime];
     }
     else
     {
         this._table = new Node[Theta.Hash.TableSizes[0]];
     }
     this._equate = equate;
     this._hash   = hash;
     this._count  = 0;
 }
Beispiel #26
0
 /// <summary>Constructs a new hash table instance.</summary>
 /// <remarks>Runtime: O(stepper).</remarks>
 public Set(Equate <T> equate, Hash <T> hash, int expectedCount)
 {
     if (expectedCount > 0)
     {
         int prime = (int)(expectedCount * (1 / _maxLoadFactor));
         while (Towel.Mathematics.Compute.IsPrime(prime))
         {
             prime++;
         }
         this._table = new STRUCTURE[prime];
     }
     else
     {
         this._table = new STRUCTURE[Towel.Hash.TableSizes[0]];
     }
     this._equate = equate;
     this._hash   = hash;
     this._count  = 0;
 }
Beispiel #27
0
 /// <summary>Constructs a new hash table instance.</summary>
 /// <remarks>Runtime: O(stepper).</remarks>
 public MapHashLinked(Equate <K> equate, Hash <K> hash, int expectedCount)
 {
     if (expectedCount > 0)
     {
         int prime = (int)(expectedCount * (1 / _maxLoadFactor));
         while (!Compute.IsPrime(prime))
         {
             prime++;
         }
         this._table = new Node[prime];
     }
     else
     {
         this._table = new Node[Towel.Hash.TableSizes[0]];
     }
     _equate = equate;
     _hash   = hash;
     _count  = 0;
 }
Beispiel #28
0
 /// <summary>Constructs a new hash table instance.</summary>
 /// <remarks>Runtime: O(stepper).</remarks>
 public SetHashList(Equate <T> equate, Hash <T> hash, int expectedCount)
 {
     if (expectedCount > 0)
     {
         int prime = (int)(expectedCount * (1 / _maxLoadFactor));
         while (Seven.Mathematics.Compute <int> .IsPrime(prime))
         {
             prime++;
         }
         this._table = new Node[prime];
     }
     else
     {
         this._table = new Node[Seven.Hash.TableSizes[0]];
     }
     this._equate = equate;
     this._hash   = hash;
     this._count  = 0;
 }
Beispiel #29
0
        /// <summary>Looks up an item this structure by a given key.</summary>
        /// <typeparam name="T">The generic type stored in the structure.</typeparam>
        /// <typeparam name="K">The type of the key to look up.</typeparam>
        /// <param name="stepper">The structure to check against.</param>
        /// <param name="key">The key to look up.</param>
        /// <param name="equate">Delegate for equating two instances of different types.</param>
        /// <returns>The item with the corresponding to the given key.</returns>
        public static T Get <T, K>(this StepperBreak <T> stepper, K key, Equate <T, K> equate)
        {
            bool contains = false;
            T    item     = default(T);

            stepper((T step) =>
            {
                if (equate(step, key))
                {
                    contains = true;
                    item     = step;
                    return(StepStatus.Break);
                }
                return(StepStatus.Continue);
            });
            if (contains == false)
            {
                throw new System.InvalidOperationException("item not found in structure");
            }
            return(item);
        }
Beispiel #30
0
 /// <summary>Constructs a hashed set.</summary>
 /// <param name="equate">The equate delegate.</param>
 /// <param name="hash">The hashing function.</param>
 /// <param name="expectedCount">The expected count of the set.</param>
 /// <runtime>O(1)</runtime>
 public SetHashLinked(
     Equate <T> equate = null,
     Hash <T> hash     = null,
     int?expectedCount = null)
 {
     if (expectedCount.HasValue && expectedCount.Value > 0)
     {
         int tableSize = (int)(expectedCount.Value * (1 / _maxLoadFactor));
         while (!IsPrime(tableSize))
         {
             tableSize++;
         }
         _table = new Node[tableSize];
     }
     else
     {
         _table = new Node[2];
     }
     _equate = equate ?? Towel.Equate.Default;
     _hash   = hash ?? Towel.Hash.Default;
     _count  = 0;
 }