Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1.     class cListSet {
  2.         const int DIVISIONS = 128;
  3.  
  4.         List<cListEntry>[] entries = new List<cListEntry>[DIVISIONS];
  5.  
  6.         public bool Add( cListEntry entry ) {
  7.             int hash = entry.GetHashCode();
  8.  
  9.             if( entries[hash] == null ) {
  10.                 // no entry for this hash group exist, adding new
  11.                 entries[hash] = new List<cListEntry>();
  12.                 entries[hash].Add( entry );
  13.                 return true;
  14.  
  15.             } else {
  16.                 // at least the hash group exists
  17.                 List<cListEntry> group = entries[hash];
  18.                 int index = group.IndexOf(entry);
  19.  
  20.                 if( index != -1 ) {
  21.                     // entry exists, update
  22.                     group[index].lastupdate = DateTime.Now;
  23.                     return false;
  24.  
  25.                 } else {
  26.                     // entry does not exist, add
  27.                     group.Add( entry );
  28.                     return true;
  29.                 }
  30.             }
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement