public void Insert(int surr) { int widx = surr / 64; int bidx = (int)(surr % 64); int len = bitmap.Length; if (widx >= len) { int newLen = 2 * len; while (widx >= newLen) { newLen *= 2; } long[] newBitmap = new long[newLen]; Array.Copy(bitmap, newBitmap, len); bitmap = newBitmap; } long mask = bitmap[widx]; if (!Miscellanea.BitIsSet64(mask, bidx)) { bitmap[widx] = mask | (1L << bidx); count++; } // Debug.Assert(count == LiveCount()); }
// public static string IntToBinaryString(int number) { // string binStr = ""; // while (number != 0) { // binStr = (number & 1) + binStr; // number = number >>> 1; // } // if (binStr == "") // binStr = "0"; // return binStr; // } // // public static string IntToBinaryString(long number) { // string binStr = ""; // while (number > 0) { // binStr = (number & 1) + binStr; // number = number >>> 1; // } // if (binStr == "") // binStr = "0"; // return binStr; // } ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// public static Obj Copy(UnaryTable[] tables) { int count = 0; for (int i = 0; i < tables.Length; i++) { count += tables[i].count; } if (count == 0) { return(EmptyRelObj.singleton); } Obj[] objs = new Obj[count]; int next = 0; for (int i = 0; i < tables.Length; i++) { UnaryTable table = tables[i]; SurrObjMapper mapper = table.mapper; long[] bitmap = table.bitmap; for (int j = 0; j < bitmap.Length; j++) { long mask = bitmap[j]; for (int k = 0; k < 64; k++) { if (Miscellanea.BitIsSet64(mask, k)) { objs[next++] = mapper(k + 64 * j); } } } } Debug.Assert(next == count); return(Builder.CreateSet(objs, objs.Length)); }
public void Finish() { if (clear) { int len = bitmapCopy.Length; for (int i = 0; i < len; i++) { long mask = bitmapCopy[i]; int offset = 64 * i; for (int j = 0; j < 64; j++) { if (Miscellanea.BitIsSet64(mask, j)) { store.Release(offset + j); } } } } else { for (int i = 0; i < deleteCount; i++) { int surr = deleteList[i]; if (surr != -1) { store.Release(surr); } } } }
int LiveCount() { int liveCount = 0; for (int i = 0; i < bitmap.Length; i++) { long mask = bitmap[i]; for (int j = 0; j < 64; j++) { if (Miscellanea.BitIsSet64(mask, j)) { liveCount++; } } } return(liveCount); }
public void Delete(int surr) { Debug.Assert(surr < 64 * bitmap.Length); int widx = surr / 64; if (widx < bitmap.Length) { long mask = bitmap[widx]; int bidx = (int)surr % 64; if (Miscellanea.BitIsSet64(mask, bidx)) { bitmap[widx] = mask & ~(1L << bidx); count--; } } // Debug.Assert(count == LiveCount()); }
public bool Contains(int surr) { int widx = surr / 64; return(widx < bitmap.Length && Miscellanea.BitIsSet64(bitmap[widx], surr % 64)); }