public static BytesToString ( byte bytes ) : string | ||
bytes | byte | |
return | string |
public void Load(byte[] serialization) { int index = 0; int byteCount = serialization.Length; if (this.values.Count != 0 || this.keys.Count != 0) { throw new BplusTreeException("load into nonempty xBucket not permitted"); } while (index < byteCount) { // get key prefix and key int keylength = BufferFile.Retrieve(serialization, index); index += BufferFile.INTSTORAGE; byte[] keybytes = new byte[keylength]; Array.Copy(serialization, index, keybytes, 0, keylength); string keystring = BplusTree.BytesToString(keybytes); index += keylength; // get value prefix and value int valuelength = BufferFile.Retrieve(serialization, index); index += BufferFile.INTSTORAGE; byte[] valuebytes = new byte[valuelength]; Array.Copy(serialization, index, valuebytes, 0, valuelength); // record new key and value this.keys.Add(keystring); this.values.Add(valuebytes); index += valuelength; } if (index != byteCount) { throw new BplusTreeException("bad byte count in serialization " + byteCount); } }
public override string PrefixForByteCount(string s, int maxbytecount) { byte[] inputbytes = BplusTree.StringToBytes(s); MD5 d = MD5.Create(); byte[] digest = d.ComputeHash(inputbytes); var resultbytes = new byte[maxbytecount]; // copy digest translating to printable ascii for (int i = 0; i < maxbytecount; i++) { int r = digest[i % digest.Length]; if (r > 127) { r = 256 - r; } if (r < 0) { r = -r; } //Console.WriteLine(" before "+i+" "+r); r = r % 79 + 40; // printable ascii //Console.WriteLine(" "+i+" "+r); resultbytes[i] = (byte)r; } string result = BplusTree.BytesToString(resultbytes); return(result); }