Esempio n. 1
0
        protected ObjRefStore RemoveEntryForKey(Type entityType, sbyte idIndex, Object id)
        {
            int hash = Hash(ExtractHash(entityType, id, idIndex));

            ObjRefStore[] table = this.table;
            int           i     = hash & (table.Length - 1);
            ObjRefStore   entry = table[i];

            if (entry != null)
            {
                if (EqualKeys(entityType, id, idIndex, entry))
                {
                    table[i] = entry.NextEntry;
                    EntryRemoved(entry);
                    return(entry);
                }
                ObjRefStore prevEntry = entry;
                entry = entry.NextEntry;
                while (entry != null)
                {
                    if (EqualKeys(entityType, id, idIndex, entry))
                    {
                        prevEntry.NextEntry = entry.NextEntry;
                        EntryRemoved(entry);
                        return(entry);
                    }
                    prevEntry = entry;
                    entry     = entry.NextEntry;
                }
            }
            return(null);
        }
Esempio n. 2
0
        public void ToString(StringBuilder sb)
        {
            sb.Append(Count).Append(" items: [");
            bool first = true;

            ObjRefStore[] table = this.table;
            for (int a = table.Length; a-- > 0;)
            {
                ObjRefStore entry = table[a];
                while (entry != null)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(',');
                    }
                    StringBuilderUtil.AppendPrintable(sb, entry);
                    entry = entry.NextEntry;
                }
            }
            sb.Append(']');
        }
Esempio n. 3
0
        public override ObjRefStore CreateObjRefStore(Type entityType, sbyte idIndex, Object id)
        {
            IObjRefStoreFactory objRefConstructorDelegate = constructorDelegateMap.Get(entityType, idIndex);

            if (objRefConstructorDelegate == null)
            {
                objRefConstructorDelegate = BuildDelegate(entityType, idIndex);
            }
            ObjRefStore objRefStore = objRefConstructorDelegate.CreateObjRef();

            objRefStore.Id = id;
            return(objRefStore);
        }
Esempio n. 4
0
        protected ObjRefStore AddEntry(Type entityType, Object id, sbyte idIndex, int bucketIndex)
        {
            ObjRefStore[] table = this.table;
            ObjRefStore   e     = table[bucketIndex];

            e = CreateEntry(entityType, id, idIndex, e);
            table[bucketIndex] = e;
            EntryAdded(e);
            if (Count >= threshold)
            {
                Resize(2 * table.Length);
            }
            return(e);
        }
Esempio n. 5
0
        public Object[] ToArray()
        {
            int index = 0;

            Object[]      targetArray = new Object[Count];
            ObjRefStore[] table       = this.table;
            for (int a = table.Length; a-- > 0;)
            {
                ObjRefStore entry = table[a];
                while (entry != null)
                {
                    targetArray[index++] = entry;
                    entry = entry.NextEntry;
                }
            }
            return(targetArray);
        }
Esempio n. 6
0
        public ObjRefStore Get(Type entityType, sbyte idIndex, Object id)
        {
            int hash = Hash(ExtractHash(entityType, id, idIndex));

            ObjRefStore[] table = this.table;
            int           i     = hash & (table.Length - 1);
            ObjRefStore   entry = table[i];

            while (entry != null)
            {
                if (EqualKeys(entityType, id, idIndex, entry))
                {
                    return(entry);
                }
                entry = entry.NextEntry;
            }
            return(null);
        }
Esempio n. 7
0
        protected void Transfer(ObjRefStore[] newTable)
        {
            int newCapacityMinus1 = newTable.Length - 1;

            ObjRefStore[] table = this.table;

            for (int a = table.Length; a-- > 0;)
            {
                ObjRefStore entry = table[a], next;
                while (entry != null)
                {
                    next = entry.NextEntry;
                    int hash = Hash(ExtractHash(entry.RealType, entry.Id, entry.IdNameIndex));
                    int i    = hash & newCapacityMinus1;
                    entry.NextEntry = newTable[i];
                    newTable[i]     = entry;
                    entry           = next;
                }
            }
        }
Esempio n. 8
0
        public void Clear()
        {
            if (IsEmpty)
            {
                return;
            }
            ObjRefStore[] table = this.table;

            for (int a = table.Length; a-- > 0;)
            {
                ObjRefStore entry = table[a];
                if (entry != null)
                {
                    table[a] = null;
                    while (entry != null)
                    {
                        ObjRefStore nextEntry = entry.NextEntry;
                        EntryRemoved(entry);
                        entry = nextEntry;
                    }
                }
            }
        }
Esempio n. 9
0
 protected void EntryRemoved(ObjRefStore e)
 {
     size--;
 }
Esempio n. 10
0
 protected void EntryAdded(ObjRefStore e)
 {
     size++;
 }
Esempio n. 11
0
 protected ObjRefStore CreateEntry(Type entityType, Object id, sbyte idIndex, ObjRefStore nextEntry)
 {
     return(objRefStoreEntryProvider.CreateObjRefStore(entityType, idIndex, id, nextEntry));
 }
Esempio n. 12
0
 public ObjRefStore Remove(ObjRefStore objRefStore)
 {
     return(RemoveEntryForKey(objRefStore.RealType, objRefStore.IdNameIndex, objRefStore.Id));
 }
Esempio n. 13
0
 protected bool EqualKeys(Type entityType, Object id, sbyte idIndex, ObjRefStore entry)
 {
     return(entry.IsEqualTo(entityType, idIndex, id));
 }
Esempio n. 14
0
 public abstract ObjRefStore CreateObjRefStore(Type entityType, sbyte idIndex, Object id, ObjRefStore nextEntry);