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++; }
public void Add(E data) { HashLinkedListNode <E> node = this; while (node.Next != null) { node = node.Next; } (node.Next = new HashLinkedListNode <E>(data)).Front = node; }
public IEnumerable <T> GetEnumerator(T startItem) { HashLinkedListNode <T> node = GetHashListNode(startItem) ?? header; while (node != null) { yield return(node.Data); node = node.Next; } }
public IEnumerator <T> GetEnumerator() { HashLinkedListNode <T> node = header; while (node != null) { yield return(node.Data); node = node.Next; } }
public IEnumerable <T> GetReverseEnumerator(T startItem) { HashLinkedListNode <T> node = GetHashListNode(startItem) ?? last; while (node != null) { yield return(node.Data); node = node.Front; } }
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); } }
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); }
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; } } }
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; } } }
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); }
public E FindElement(Predicate <E> func) { HashLinkedListNode <E> node = Find(func); return(node != null ? node.Data : default(E)); }
public void Clear() { hashtable = new HashLinkedListNode <HashLinkedListNode <T> > [BaseSize]; header = last = null; count = 0; }