Example #1
0
        public virtual int GetRandomBit(int type, int cnt)
        {
            RandomBit v = null;

            if (map.TryGetValue(type, out v))
            {
                return(v.Random());
            }
            return(0);
        }
Example #2
0
        public virtual RandomBit AddRandomBit(int type, int cnt)
        {
            RandomBit v = null;

            if (!map.TryGetValue(type, out v))
            {
                v         = new RandomBit(cnt);
                map[type] = v;
            }
            return(v);
        }
Example #3
0
        public virtual void Clear(int type)
        {
            RandomBit v = null;

            if (map.TryGetValue(type, out v))
            {
                int len = (v.array == null ? 0 : v.array.Length);
                v.index = len - 1;
                for (int i = 0; i < len; i++)
                {
                    v.array[i] = i;
                }
            }
        }
Example #4
0
        public virtual bool ExsitIndex(int type, int pos)
        {
            RandomBit v = null;

            if (map.TryGetValue(type, out v))
            {
                for (int i = 0; i <= v.index; i++)
                {
                    if (v.array[i] == pos)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #5
0
        public virtual void Remove(int type, int pos)
        {
            RandomBit v = null;

            if (map.TryGetValue(type, out v))
            {
                int indexOfPos = 0;
                for (int i = 0, maxi = (v.array == null ? 0 : v.array.Length); i < maxi; i++)
                {
                    if (v.array[i] == pos)
                    {
                        indexOfPos = i;
                    }
                }
                v.index++;
                int r = v.array[v.index];
                v.array[v.index]    = pos;
                v.array[indexOfPos] = r;
            }
        }