コード例 #1
0
ファイル: ObjStoreUpdater.cs プロジェクト: cell-lang/csharp
        private void InsertIntoHashtable(int index, int hashcode)
        {
            int hashIdx = Miscellanea.UnsignedRemaider(hashcode, hashRange);

            buckets[index]     = hashtable[hashIdx];
            hashtable[hashIdx] = index;
        }
コード例 #2
0
        private void RemoveFromHashtable(int index)
        {
            int hashcode = hashcodeOrNextFree[index];
            int hashIdx  = Miscellanea.UnsignedRemaider(hashcode, hashtable.Length);
            int idx      = hashtable[hashIdx];

            Debug.Assert(idx != -1);

            if (idx == index)
            {
                hashtable[hashIdx] = buckets[index];
                // buckets[index] = -1; // NOT STRICTLY NECESSARY...
                return;
            }

            int prevIdx = idx;

            idx = buckets[idx];
            while (idx != index)
            {
                prevIdx = idx;
                idx     = buckets[idx];
                Debug.Assert(idx != -1);
            }

            buckets[prevIdx] = buckets[index];
            // buckets[index] = -1; // NOT STRICTLY NECESSARY
        }
コード例 #3
0
        public void Delete(int index, int hashcode)
        {
            int hashIdx = Miscellanea.UnsignedRemaider(hashcode, hashtable.Length);
            int head    = hashtable[hashIdx];

            Debug.Assert(head != Empty);

            if (head == index)
            {
                hashtable[hashIdx] = buckets[index];
                buckets[index]     = Empty;
                return;
            }

            int curr = head;

            for ( ; ;)
            {
                int next = buckets[curr];
                Debug.Assert(next != Empty);
                if (next == index)
                {
                    buckets[curr] = buckets[next];
                    buckets[next] = Empty;
                    return;
                }
                curr = next;
            }
        }
コード例 #4
0
        public void Insert(int index, int hashcode)
        {
            Debug.Assert(buckets[index] == Empty);
            Debug.Assert(index < buckets.Length);

            int hashIdx = Miscellanea.UnsignedRemaider(hashcode, hashtable.Length);
            int head    = hashtable[hashIdx];

            hashtable[hashIdx] = index;
            buckets[index]     = head;
        }
コード例 #5
0
        public int ValueToSurr(Obj value)
        {
            if (count == 0)
            {
                return(-1);
            }
            int hashcode = value.SignedHashcode();
            int hashIdx  = Miscellanea.UnsignedRemaider(hashcode, hashtable.Length);
            int idx      = hashtable[hashIdx];

            while (idx != -1)
            {
                Debug.Assert(values[idx] != null);
                if (hashcodeOrNextFree[idx] == hashcode && value.IsEq(values[idx]))
                {
                    return(idx);
                }
                idx = buckets[idx];
            }
            return(-1);
        }
コード例 #6
0
ファイル: ObjStoreUpdater.cs プロジェクト: cell-lang/csharp
        private int ValueToSurr(Obj value)
        {
            int surrogate = store.ValueToSurr(value);

            if (surrogate != -1)
            {
                return(surrogate);
            }

            if (count > 0)
            {
                int hashcode = value.SignedHashcode(); //## BAD BAD BAD: CALCULATING THE HASHCODE TWICE

                if (hashRange == 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (hashcodes[i] == hashcode && values[i].IsEq(value))
                        {
                            return(surrogates[i]);
                        }
                    }
                }
                else
                {
                    int hashIdx = Miscellanea.UnsignedRemaider(hashcode, hashRange);
                    for (int i = hashtable[hashIdx]; i != -1; i = buckets[i])
                    {
                        if (hashcodes[i] == hashcode && values[i].IsEq(value))
                        {
                            return(surrogates[i]);
                        }
                    }
                }
            }

            return(-1);
        }
コード例 #7
0
ファイル: IntStoreUpdater.cs プロジェクト: cell-lang/csharp
        private int ValueToSurr(long value)
        {
            int surrogate = store.ValueToSurr(value);

            if (surrogate != -1)
            {
                return(surrogate);
            }

            if (count > 0)
            {
                if (hashRange == 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        if (values[i] == value)
                        {
                            return(surrogates[i]);
                        }
                    }
                }
                else
                {
                    int hashIdx = Miscellanea.UnsignedRemaider(Hashcode(value), hashRange);
                    for (int i = hashtable[hashIdx]; i != -1; i = buckets[i])
                    {
                        if (values[i] == value)
                        {
                            return(surrogates[i]);
                        }
                    }
                }
            }

            return(-1);
        }
コード例 #8
0
 public int Head(int hashcode)
 {
     return(hashtable[Miscellanea.UnsignedRemaider(hashcode, hashtable.Length)]);
 }