private void FillKey(BytesWritable o) { int len = keyLenRNG.NextInt(); if (len < MinKeyLen) { len = MinKeyLen; } o.SetSize(len); int n = MinKeyLen; while (n < len) { byte[] word = dict[random.Next(dict.Length)]; int l = Math.Min(word.Length, len - n); System.Array.Copy(word, 0, o.Get(), n, l); n += l; } if (sorted && WritableComparator.CompareBytes(lastKey.Get(), MinKeyLen, lastKey.GetSize () - MinKeyLen, o.Get(), MinKeyLen, o.GetSize() - MinKeyLen) > 0) { IncrementPrefix(); } System.Array.Copy(prefix, 0, o.Get(), 0, MinKeyLen); lastKey.Set(o); }
public virtual void Next(BytesWritable key) { key.SetSize(Math.Max(MinKeyLen, keyLenRNG.NextInt())); random.NextBytes(key.Get()); int n = random.Next(max - min) + min; byte[] b = key.Get(); b[0] = unchecked ((byte)(n >> 24)); b[1] = unchecked ((byte)(n >> 16)); b[2] = unchecked ((byte)(n >> 8)); b[3] = unchecked ((byte)n); }
private void FillValue(BytesWritable o) { int len = valLenRNG.NextInt(); o.SetSize(len); int n = 0; while (n < len) { byte[] word = dict[random.Next(dict.Length)]; int l = Math.Min(word.Length, len - n); System.Array.Copy(word, 0, o.Get(), n, l); n += l; } }
public KVGenerator(Random random, bool sorted, RandomDistribution.DiscreteRNG keyLenRNG , RandomDistribution.DiscreteRNG valLenRNG, RandomDistribution.DiscreteRNG wordLenRNG , int dictSize) { this.random = random; dict = new byte[dictSize][]; this.sorted = sorted; this.keyLenRNG = keyLenRNG; this.valLenRNG = valLenRNG; for (int i = 0; i < dictSize; ++i) { int wordLen = wordLenRNG.NextInt(); dict[i] = new byte[wordLen]; random.NextBytes(dict[i]); } lastKey = new BytesWritable(); FillKey(lastKey); }