Example #1
0
        public void Add(T item)
        {
            HashLinkedListNode <T> newData = null;
            uint index = (uint)item.GetHashCode() % BaseSize;

            if (hashtable[index] == null)
            {
                hashtable[index] = new HashLinkedListNode <HashLinkedListNode <T> >(newData = new HashLinkedListNode <T>(item));
            }
            else if (hashtable[index].Find(node => node.Data.Equals(item)) != null)
            {
                throw new Exception("不能重复添加项");
            }
            else
            {
                hashtable[index].Add(newData = new HashLinkedListNode <T>(item));
            }
            if (header == null)
            {
                header = last = newData;
            }
            else
            {
                last.Next     = newData;
                newData.Front = last;
                last          = newData;
            }
            count++;
        }
Example #2
0
            public void Add(E data)
            {
                HashLinkedListNode <E> node = this;

                while (node.Next != null)
                {
                    node = node.Next;
                }
                (node.Next = new HashLinkedListNode <E>(data)).Front = node;
            }
Example #3
0
        public IEnumerable <T> GetEnumerator(T startItem)
        {
            HashLinkedListNode <T> node = GetHashListNode(startItem) ?? header;

            while (node != null)
            {
                yield return(node.Data);

                node = node.Next;
            }
        }
Example #4
0
        public IEnumerator <T> GetEnumerator()
        {
            HashLinkedListNode <T> node = header;

            while (node != null)
            {
                yield return(node.Data);

                node = node.Next;
            }
        }
Example #5
0
        public IEnumerable <T> GetReverseEnumerator(T startItem)
        {
            HashLinkedListNode <T> node = GetHashListNode(startItem) ?? last;

            while (node != null)
            {
                yield return(node.Data);

                node = node.Front;
            }
        }
Example #6
0
            public bool Action(Predicate <E> func, Action <HashLinkedListNode <E> > action)
            {
                HashLinkedListNode <E> node = Find(func);

                if (node != null)
                {
                    action(node);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Example #7
0
            public HashLinkedListNode <E> Find(Predicate <E> func)
            {
                HashLinkedListNode <E> node = this;

                while (node != null)
                {
                    if (func(node.Data))
                    {
                        return(node);
                    }
                    node = node.Next;
                }
                return(null);
            }
Example #8
0
        public IEnumerable <T> GetReverseEnumeratorOver(T endItem)
        {
            if (header != null)
            {
                HashLinkedListNode <T> end  = (GetHashListNode(endItem) ?? header).Front;
                HashLinkedListNode <T> node = last;
                while (node != null)
                {
                    yield return(node.Data);

                    node = node.Front;
                }
            }
        }
Example #9
0
        public IEnumerable <T> GetEnumeratorOver(T endItem)
        {
            if (last != null)
            {
                HashLinkedListNode <T> end  = (GetHashListNode(endItem) ?? last).Next;
                HashLinkedListNode <T> node = header;
                while (node != end)
                {
                    yield return(node.Data);

                    node = node.Next;
                }
            }
        }
Example #10
0
        public bool Remove(T item)
        {
            uint index = (uint)item.GetHashCode() % BaseSize;

            if (hashtable[index] != null)
            {
                return(hashtable[index].Action(node => node.Data.Equals(item), node => {
                    HashLinkedListNode <T> itemNode = node.Data;
                    if (itemNode.Front != null)
                    {
                        itemNode.Front.Next = itemNode.Next;
                    }
                    else
                    {
                        header = itemNode.Next;
                    }
                    if (itemNode.Next != null)
                    {
                        itemNode.Next.Front = itemNode.Front;
                    }
                    else
                    {
                        last = itemNode.Front;
                    }
                    if (hashtable[index] == node)
                    {
                        hashtable[index] = node.Next;
                        if (hashtable[index] != null)
                        {
                            hashtable[index].Front = null;
                        }
                    }
                    else
                    {
                        node.Front.Next = node.Next;
                        if (node.Next != null)
                        {
                            node.Next.Front = node.Front;
                        }
                    }
                    count--;
                }));
            }
            return(false);
        }
Example #11
0
            public E FindElement(Predicate <E> func)
            {
                HashLinkedListNode <E> node = Find(func);

                return(node != null ? node.Data : default(E));
            }
Example #12
0
 public void Clear()
 {
     hashtable = new HashLinkedListNode <HashLinkedListNode <T> > [BaseSize];
     header    = last = null;
     count     = 0;
 }