/// <summary> /// Adds the item. Does NOT check for whether the item is already present. /// </summary> private NormStr AddCore(ReadOnlyMemory <char> str, uint hash) { Contracts.Assert(str.Length >= 0); Contracts.Assert(Hashing.HashString(str.Span) == hash); if (_rgns == null) { Contracts.Assert(_cns == 0); _rgmeta = new ulong[10]; _rgns = new NormStr[10]; } else if (_cns >= _rgns.Length) { Contracts.Assert(_cns == _rgns.Length); int size = checked (_rgns.Length / 2 + _rgns.Length); Array.Resize(ref _rgmeta, size); Array.Resize(ref _rgns, size); } Contracts.Assert(_cns < _rgns.Length); NormStr ns = new NormStr(str, _cns, hash); int iins = GetIins(hash); _rgns[_cns] = ns; _rgmeta[_cns] = Utils.MakeUlong((uint)_rgins[iins], (uint)ns.Value.Length); _rgins[iins] = _cns; if (++_cns >= _rgins.Length) { GrowTable(); } AssertValid(); return(ns); }
private void GrowTable() { AssertValid(); int size = checked (2 * _rgins.Length); _rgins = new int[size]; _mask = size - 1; for (int i = 0; i < _rgins.Length; i++) { _rgins[i] = -1; } for (int ins = 0; ins < _cns; ins++) { var ns = GetNs(ins); int iins = GetIins(ns._hash); _rgmeta[ins] = Utils.MakeUlong((uint)_rgins[iins], (uint)ns.Value.Length); _rgins[iins] = ins; } AssertValid(); }