public FoundTreePage(long number, TreePage page, Slice firstKey, Slice lastKey, long[] cursorPath, ByteStringContext.Scope firstScope, ByteStringContext.Scope lastScope) { Number = number; Page = page; FirstKey = firstKey; LastKey = lastKey; CursorPath = cursorPath; _firstScope = firstScope; _lastScope = lastScope; }
public static List <Tuple <Slice, Slice> > GenerateUniqueRandomSlicePairs(int amount, int keyLength, int?randomSeed = null) { Debug.Assert(amount > 0); Debug.Assert(keyLength > 0); // Generate random key value pairs var generator = randomSeed.HasValue ? new Random(randomSeed.Value) : new Random(); var keyBuffer = new byte[keyLength]; // This serves to ensure the uniqueness of keys globally (that way // we know the exact number of insertions) var added = new HashSet <Slice>(SliceComparer.Instance); var pairs = new List <Tuple <Slice, Slice> >(); int i = 0; while (pairs.Count < amount) { Slice key; Slice value; generator.NextBytes(keyBuffer); ByteStringContext.Scope keyScope = Slice.From(Configuration.Allocator, keyBuffer, ByteStringType.Immutable, out key); i++; if (added.Contains(key)) { // Release the unused key's memory keyScope.Dispose(); continue; } // Trees are mostly used by Table to store long values. We // attempt to emulate that behavior long valueBuffer = generator.Next(); valueBuffer += (long)generator.Next() << 32; valueBuffer += (long)generator.Next() << 64; valueBuffer += (long)generator.Next() << 96; unsafe { Slice.From(Configuration.Allocator, (byte *)&valueBuffer, sizeof(long), ByteStringType.Immutable, out value); } pairs.Add(new Tuple <Slice, Slice>(key, value)); added.Add(key); } return(pairs); }