示例#1
0
        /// <summary>
        /// Second type to search
        /// </summary>
        /// <param name="searchedKey"></param> The key that it is needed to search.
        /// <returns></returns>
        public HashNode <T> Search(string searchedKey)
        {
            int code = GetCode(searchedKey);

            if (HashTable[code] != null)
            {
                if (HashTable[code].Key != searchedKey)
                {
                    HashNode <T> Aux = HashTable[code];
                    while (Aux.Key != searchedKey && Aux.Next != null)
                    {
                        Aux = Aux.Next;
                    }
                    if (Aux.Key == searchedKey)
                    {
                        return(Aux);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(HashTable[code]);
                }
            }
            else
            {
                return(null);
            }
        }
示例#2
0
        /// <summary>
        /// Get a list of all nodes in the hash
        /// </summary>
        public List <HashNode <T> > GetAsNodes()
        {
            var returnList  = new List <HashNode <T> >();
            var currentNode = new HashNode <T>();

            foreach (var task in HashTable)
            {
                currentNode = task;
                while (currentNode != null)
                {
                    returnList.Add(currentNode);
                    currentNode = currentNode.Next;
                }
            }
            return(returnList);
        }
示例#3
0
        /// <summary>
        /// Get a list of items that fulfill a condition
        /// </summary>
        /// <param name="predicate"></param> The condition to add to the list
        /// <returns></returns>
        public List <T> GetFilterList(Func <T, bool> predicate)
        {
            List <T> FiltedList  = new List <T>();
            var      currentNode = new HashNode <T>();

            foreach (var task in HashTable)
            {
                currentNode = task;
                while (currentNode != null)
                {
                    if (predicate(currentNode.Value))
                    {
                        FiltedList.Add(currentNode.Value);
                    }
                    currentNode = currentNode.Next;
                }
            }
            return(FiltedList);
        }
示例#4
0
        /// <summary>
        /// Inserts a new node into the hash.
        /// </summary>
        /// <param name="InsertV"></param> The value of the node that is being inserted
        /// <param name="key"></param> The key used to add into the Hash
        public void Insert(T InsertV, string key)
        {
            HashNode <T> T1 = new HashNode <T>();

            T1.Value = InsertV;
            T1.Key   = key;
            int code = GetCode(T1.Key);

            if (HashTable[code] != null)
            {
                HashNode <T> Aux = HashTable[code];
                while (Aux.Next != null)
                {
                    Aux = Aux.Next;
                }
                Aux.Next    = T1;
                T1.Previous = Aux;
            }
            else
            {
                HashTable[code] = T1;
            }
        }
示例#5
0
        /// <summary>
        /// Second type of insert
        /// </summary>
        /// <param name="InsertV"></param> Value of the new node.
        /// <param name="key"></param> Key used to insert the new node.
        /// <param name="multiplier"></param> Number used to establish the range used for the series .
        public void Insert(T InsertV, string key, int multiplier)
        {
            HashNode <T> T1 = new HashNode <T>();

            T1.Value = InsertV;
            T1.Key   = key;
            int Originalcode = GetCode(T1.Key, multiplier);
            int code         = Originalcode;

            if (HashTable[code] != null)
            {
                while (HashTable[code] != null)
                {
                    if (code >= (multiplier + 1) * 10)
                    {
                        code = multiplier * 10;
                    }
                    else
                    {
                        code += 1;
                        //if (code == Originalcode)
                        //{
                        //    avoid enqueue
                        //}
                    }
                }
                if (HashTable[code] == null)
                {
                    HashTable[code] = T1;
                }
            }
            else
            {
                HashTable[code] = T1;
            }
        }