Beispiel #1
0
        internal bool TryGet(TKey key, out GroupBuffer <TVal> val)
        {
            var hashCode = Hash(key);

            for (var index = buckets[hashCode % buckets.Length] - 1; index >= 0u; index = Nexts[index])
            {
                if (HashCodes[index] == hashCode && comparer.Equals(Keys[index], key))
                {
                    val = Vals[index];
                    return(true);
                }
            }

            val = default(GroupBuffer <TVal>);
            return(false);
        }
Beispiel #2
0
        public void Add(TKey key, TVal val)
        {
            var hashCode = Hash(key);

            for (var index = buckets[hashCode % buckets.Length] - 1; index >= 0; index = Nexts[index])
            {
                if (HashCodes[index] != hashCode || !comparer.Equals(Keys[index], key))
                {
                    continue;
                }

                Vals[index].Add(val);
                return;
            }

            int index1;

            if (freeList >= 0)
            {
                index1   = freeList;
                freeList = Nexts[index1];
            }
            else
            {
                if (count == Vals.Length)
                {
                    Resize();
                }

                index1 = count;
                ++count;
            }

            var index2 = hashCode % buckets.Length;

            HashCodes[index1] = hashCode;

            Keys[index1] = key;

            var buff = GroupBuffer <TVal> .CreateBuff(1u);

            Vals[index1] = buff;
            buff.Add(val);

            Nexts[index1]   = buckets[index2] - 1;
            buckets[index2] = index1 + 1;
        }
Beispiel #3
0
        private void Resize()
        {
            var length   = checked (count * 2 + 1);
            var numArray = new int[length];

            var newVals = new GroupBuffer <TVal> [length];

            Array.Copy(Vals, 0, newVals, 0, count);
            Vals = newVals;

            var newKeys = new TKey[length];

            Array.Copy(Keys, 0, newKeys, 0, count);
            Keys = newKeys;

            var newHashLists = new int[length];

            Array.Copy(HashCodes, 0, newHashLists, 0, count);
            HashCodes = newHashLists;
            GroupUtility.Memset(HashCodes, (uint)count);

            var newNexts = new int[length];

            Array.Copy(Nexts, 0, newNexts, 0, count);
            Nexts = newNexts;

            unsafe
            {
                fixed(int *pointNumArr = numArray, ptrHash = HashCodes, ptrNexts = Nexts)
                {
                    for (var index1 = 0u; index1 < (uint)count; ++index1)
                    {
                        var index2 = ptrHash[index1] % length;
                        ptrNexts[index1]    = pointNumArr[index2] - 1;
                        pointNumArr[index2] = (int)(index1 + 1);
                    }
                }
            }

            buckets = numArray;
        }
Beispiel #4
0
        public JoinOperator(
            ref TCollect collect,
            ref TSecond second,
            ref TSelector selector,
            ref TSelector2 selector2,
            ref TResSelector resSelector,
            ref TComparer comparer)
        {
            _collect     = collect;
            _selector    = selector;
            _resSelector = resSelector;

            _keyGroupMeta = KeyGroupMeta <TKey, T2, TComparer> .Create(ref comparer);

            _keyGroupMeta.Fill(ref second, ref selector2);

            _buffIndex = -1;
            _indexVal  = -1;

            _item           = default(TRes);
            _nowGetFromBuff = false;
            _curBuff        = default(GroupBuffer <T2>);
            _itemForCombine = default(T);
        }
Beispiel #5
0
 internal GroupingArray(GroupBuffer <T> buff)
 {
     _buff = buff ?? Empty;
 }