private void AddCluster() { TCluster NewCluster = new TCluster(this.size); size = (int)(size * this.factor); NewCluster.next = this.FirstCluster; //New cluster is added in the beginning this.FirstCluster = NewCluster; TPosition pos = new TPosition(ref FirstCluster.next, 0); while (!(pos.cluster == FirstCluster && pos.offset == 0)) //rehash { if (Used(pos.cluster.Cluster[pos.offset])) { TEntry entry = pos.cluster.Cluster[pos.offset]; TPosition newPosition = GenerateKey(entry.u); if (newPosition.offset != pos.offset || newPosition.cluster != pos.cluster) { pos.cluster.Cluster[pos.offset] = TEntry.DirtyEntry(); this.count--; Add(entry); } } IncreaseKey(ref pos); } }
void Mark(int u) { TPosition pos = GenerateKey(u); while (!Null(pos.cluster.Cluster[pos.offset])) { if (pos.cluster.Cluster[pos.offset].u == u) { break; } IncreaseKey(ref pos); } TEntry entry = GetTEntry(pos); if (entry.GetMark() != true) { if (!IsTerminal(entry.low)) { Mark(entry.low); } AddMark(ref pos); if (!IsTerminal(entry.high)) { Mark(entry.high); } } }
public void Remove(int u) { TPosition pos = GenerateKey(u); while (!Null(pos.cluster.Cluster[pos.offset])) { if (pos.cluster.Cluster[pos.offset].u == u) { count--; pos.cluster.Cluster[pos.offset] = TEntry.DirtyEntry(); //Only flags dirty return; } IncreaseKey(ref pos); } }
public void Add(TEntry entry) { #if NoGC if (NeedResize()) { AddCluster(); } #endif TPosition pos = GenerateKey(entry.u); while (Used(pos.cluster.Cluster[pos.offset])) { IncreaseKey(ref pos); } pos.cluster.Cluster[pos.offset] = entry; count++; }
private static bool Dirty(TEntry entry) { return(entry.low == -1); }
private static bool Used(TEntry entry) { return(entry.GetVar() > 0 || entry.u > 0); }
private static bool Null(TEntry entry) { return(entry.u == 0 && entry.GetVar() == 0); }