Beispiel #1
0
        public JsonReaderDictionary()
        {
            var size = KeysCache.GetPrime(0);

            _buckets = new int[size];
            _buckets.AsSpan().Fill(-1);
            _bucketsLength = (ulong)size;
            _entries       = new Entry[size];
            _count         = 0;
        }
Beispiel #2
0
        public void Add(string key, TValue value)
        {
            var         bytesLength = Encoding.UTF8.GetByteCount(key);
            Span <byte> buffer      = stackalloc byte[bytesLength];

            Encoding.UTF8.GetBytes(key, buffer);

            var hashCode     = KeysCache.GetKey(buffer);
            var targetBucket = hashCode % _bucketsLength;

            if (_count == _entries !.Length)
            {
                var newSize = KeysCache.GetPrime(_count * 2);
                Resize(newSize);
                targetBucket = hashCode % _bucketsLength;
            }

            var index = _count++;

            _entries[index].HashCode = hashCode;
            _entries[index].Next     = _buckets ![targetBucket];