public SequencePool() { _mask = 31; _buckets = Utils.CreateArray <int>(_mask + 1, -1); _next = new int[10]; _start = new int[11]; _hash = new uint[10]; _bytes = new byte[40]; AssertValid(); }
public SequencePool(BinaryReader reader) { // *** Binary format *** // int: _idLim (the number of sequences) // int[]: _start (length is _idLim+1) // byte[]: _bytes (length is _start[_idLim]) _idLim = reader.ReadInt32(); Contracts.CheckDecode(0 <= _idLim && _idLim < int.MaxValue); _start = reader.ReadIntArray(_idLim + 1); Contracts.CheckDecode(Utils.Size(_start) > 0 && _start[0] == 0); Contracts.CheckDecode(_start[_idLim] >= 0); _bytes = reader.ReadByteArray(_start[_idLim]); if (_idLim < 10) { Array.Resize(ref _start, 11); } if (Utils.Size(_bytes) < 40) { Array.Resize(ref _bytes, 40); } // Find the smallest power of 2 that is greater than _idLim. int ibit = Utils.IbitHigh((uint)Math.Max(_idLim, 31)); Contracts.Assert(4 <= ibit && ibit <= 31); if (ibit < 31) { ibit++; } _mask = (1 << ibit) - 1; _buckets = Utils.CreateArray <int>(_mask + 1, -1); _hash = new uint[Math.Max(_idLim, 10)]; _next = new int[Math.Max(_idLim, 10)]; uint[] sequence = null; var cb = _start[_idLim]; for (int id = 0; id < _idLim; id++) { Contracts.CheckDecode(_start[id] <= _start[id + 1] && _start[id + 1] <= cb); int count = Leb128ToUIntArray(_bytes, _start[id], _start[id + 1], ref sequence); _hash[id] = Hashing.HashSequence(sequence, 0, count); int i = GetBucketIndex(_hash[id]); _next[id] = _buckets[i]; _buckets[i] = id; } AssertValid(); }
private void GrowTable() { AssertValid(); int size = checked (2 * _buckets.Length); _buckets = Utils.CreateArray <int>(size, -1); _mask = size - 1; for (int id = 0; id < _idLim; id++) { int i = GetBucketIndex(_hash[id]); _next[id] = _buckets[i]; _buckets[i] = id; } AssertValid(); }