Esempio n. 1
0
        private void GetItAllCascadeInt(ref List <int> indexes, ref List <int> vals, VariableBranch b, int dp, int start, int range)
        {
            var step = range / BranchSize;

            if (dp > 0)
            {
                for (var i = 0; i < BranchSize; i++)
                {
                    if (b.br[i] != null)
                    {
                        GetItAllCascadeInt(ref indexes, ref vals, b.br[i], dp - 1, start + step * i, step);
                    }
                }
            }
            else
            {
                if (range != BranchSize)
                {
                    Debug.Log("Error in range: " + range);
                }

                for (var i = 0; i < 8; i++)
                {
                    if (b.br[i] != null)
                    {
                        indexes.Add(start + i);
                        vals.Add(b.br[i].value);
                    }
                }
            }
        }
Esempio n. 2
0
        private void DiscardCascade(VariableBranch b, int dep)
        {
            if ((_brPoolMax + 1) >= _branchPool.Length)
            {
                _branchPool = _branchPool.ExpandBy(32);
            }

            if (dep > 0)
            {
                for (var i = 0; i < BranchSize; i++)
                {
                    if (b.br[i] == null)
                    {
                        continue;
                    }
                    DiscardCascade(b.br[i], dep - 1);
                    DiscardBranch(b, i);
                }
            }
            else
            {
                for (var i = 0; i < 8; i++)
                {
                    if (b.br[i] != null)
                    {
                        DiscardFruit(b, i);
                    }
                }
            }
        }
Esempio n. 3
0
        private void GetItAllCascadeBool(ref List<int> inds, VariableBranch b, int dp, int start, int range)
        {

            var step = range / BranchSize;
            if (dp > 0)
            {
                for (var i = 0; i < BranchSize; i++)
                    if (b.br[i] != null)
                        GetItAllCascadeBool(ref inds, b.br[i], dp - 1, start + step * i, step);
            }
            else
            {

                if (range != BranchSize)
                    Debug.Log("Error in range: " + range);

                for (var i = 0; i < 8; i++)
                {
                    var branch = b.br[i];
                    
                    if (branch == null) continue;
                    
                    var value = branch.value;

                    for (var j = 0; j < 32; j++)
                        if ((value & 0x00000001 << j) != 0)
                            inds.Add((start + i) * 32 + j);
                }
            }
        }
Esempio n. 4
0
        protected VariableBranch GetNewFruit()
        {
            if (_frPoolMax == 0)
            {
                var vb = new VariableBranch();

                return(vb);
            }
            _frPoolMax--;
            count++;

            return(_fruitPool[_frPoolMax]);
        }
Esempio n. 5
0
        protected void DiscardFruit(VariableBranch b, int no)
        {
            if ((_frPoolMax + 1) >= _fruitPool.Length)
                _fruitPool = _fruitPool.ExpandBy(32);

            _fruitPool[_frPoolMax] = b.br[no];
            var vb = _fruitPool[_frPoolMax];
            vb.value = 0;
            b.br[no] = null;
            b.value--;
            _frPoolMax++;
            count--;
        }
Esempio n. 6
0
 protected VariableBranch GetNewFruit()
 {
     if (_frPoolMax == 0)
     {
         var vb = new VariableBranch();
         //   Debug.Log("Creating new fruit ");
         return(vb);
     }
     _frPoolMax--;
     count++;
     // Debug.Log("Returning existing fruit");
     return(_fruitPool[_frPoolMax]);
 }
Esempio n. 7
0
        protected static VariableBranch GetNewBranch()
        {
            if (_brPoolMax == 0)
            {
                var vb = new VariableBranch() {
                    br = new VariableBranch[BranchSize]
                };

                return vb;
            }

            _brPoolMax--;
            return _branchPool[_brPoolMax];
        }
Esempio n. 8
0
        protected static void DiscardBranch(VariableBranch b, int no)
        {
            if ((_brPoolMax + 1) >= _branchPool.Length)
                _branchPool = _branchPool.ExpandBy(32);
            
            _branchPool[_brPoolMax] = b.br[no];
            VariableBranch vb = _branchPool[_brPoolMax];
            if (vb.value != 0)
                Debug.LogError("Value is " + vb.value + " on delete ");

            b.value--;
            b.br[no] = null;
            _brPoolMax++;
        }
Esempio n. 9
0
 protected static VariableBranch GetNewBranch()
 {
     if (_brPoolMax == 0)
     {
         var vb = new VariableBranch()
         {
             br = new VariableBranch[BranchSize]
         };
         //Debug.Log("Creating new branch ");
         return(vb);
     }
     _brPoolMax--;
     //Debug.Log("Returning existing branch");
     return(_branchPool[_brPoolMax]);
 }
Esempio n. 10
0
        public void Add(int ind, int val)
        {
            if (ind >= max)
            {
                while (ind >= max)
                {
                    depth++;
                    max *= BranchSize;
                    var newbr = GetNewBranch();
                    newbr.br[0] = br;
                    newbr.value++;
                    br = newbr;
                }
                path    = new VariableBranch[depth];
                pathInd = new int[depth];
            }

            var d       = depth;
            var vb      = br;
            var subSize = max;


            while (d > 0)
            {
                subSize /= BranchSize;
                var no = ind / subSize;
                ind -= no * subSize;
                if (vb.br[no] == null)
                {
                    vb.br[no] = GetNewBranch(); vb.value++;
                }
                d--;
                vb = vb.br[no];
            }

            if (vb.br[ind] == null)
            {
                vb.br[ind] = GetNewFruit();
                vb.value  += 1;
            }

            vb.br[ind].value += val;
        }
Esempio n. 11
0
        protected virtual void Set(int ind, T obj)
        {
            if (ind >= max)
            {
                if (QcSharp.IsDefaultOrNull(obj))
                {
                    return;
                }
                while (ind >= max)
                {
                    depth++;
                    max *= BranchSize;
                    var newBranch = GetNewBranch();
                    newBranch.br[0] = br;
                    newBranch.value++;
                    br = newBranch;
                }
                path    = new VariableBranch[depth];
                pathInd = new int[depth];
            }

            var d       = depth;
            var vb      = br;
            var subSize = max;

            if (!QcSharp.IsDefaultOrNull(obj))
            {
                while (d > 0)
                {
                    subSize /= BranchSize;
                    var no = ind / subSize;
                    ind -= no * subSize;
                    if (vb.br[no] == null)
                    {
                        vb.br[no] = GetNewBranch(); vb.value++;
                    }
                    d--;
                    vb = vb.br[no];
                }

                if (vb.br[ind] == null)
                {
                    vb.br[ind] = GetNewFruit();
                    vb.value  += 1;

                    var cnt = objs.Length;
                    while (_firstFreeObj < cnt && !QcSharp.IsDefaultOrNull(objs[_firstFreeObj]))
                    {
                        _firstFreeObj++;
                    }
                    if (_firstFreeObj >= cnt)
                    {
                        Expand(ref objs, BranchSize);
                    }

                    objs[_firstFreeObj] = obj;
                    vb.br[ind].value    = _firstFreeObj;
                }
                else
                {
                    objs[vb.br[ind].value] = obj;
                }
            }
            else
            {
                while (d > 0)
                {
                    subSize /= BranchSize;
                    var no = ind / subSize;
                    ind -= no * subSize;
                    if (vb.br[no] == null)
                    {
                        return;
                    }
                    d--;
                    path[d]    = vb;
                    pathInd[d] = no;
                    vb         = vb.br[no];
                }

                if (vb.br[ind] == null)
                {
                    return;
                }

                var ar = vb.br[ind].value;

                objs[ar]      = default;
                _firstFreeObj = Mathf.Min(_firstFreeObj, ar);

                DiscardFruit(vb, ind);

                while (d < depth)
                {
                    if (vb.value > 0)
                    {
                        return;
                    }
                    vb = path[d];
                    DiscardBranch(vb, pathInd[d]);
                    d++;
                }

                TryReduceDepth();
            }
        }
Esempio n. 12
0
        public bool Toggle(int ind)
        {
            var bitNo = ind % 32;

            ind /= 32;

            if (ind >= max)
            {
                while (ind >= max)
                {
                    depth++;
                    max *= BranchSize;
                    var newbr = GetNewBranch();
                    newbr.br[0] = br;
                    newbr.value++;
                    br = newbr;
                }
                path    = new VariableBranch[depth];
                pathInd = new int[depth];
            }

            var d       = depth;
            var vb      = br;
            var subSize = max;


            while (d > 0)
            {
                subSize /= BranchSize;
                var no = ind / subSize;
                ind -= no * subSize;
                if (vb.br[no] == null)
                {
                    vb.br[no] = GetNewBranch(); vb.value++;
                }
                d--;
                path[d]    = vb;
                pathInd[d] = no;
                vb         = vb.br[no];
            }

            if (vb.br[ind] == null)
            {
                vb.br[ind] = GetNewFruit();
                vb.value  += 1;
            }

            var fvb = vb.br[ind];

            fvb.value ^= 0x00000001 << bitNo;

            var result = ((fvb.value & 0x00000001 << bitNo) != 0);

            if (fvb.value == 0)
            {
                DiscardFruit(vb, ind);
            }

            while (d < depth)
            {
                if (vb.value > 0)
                {
                    return(result);
                }
                vb = path[d];
                DiscardBranch(vb, pathInd[d]);
                d++;
            }

            TryReduceDepth();

            return(result);
        }
Esempio n. 13
0
        private void Set(int ind, bool val)
        {
            var bitNo = ind % 32;

            ind /= 32;

            if (ind >= max)
            {
                if (!val)
                {
                    return;
                }
                while (ind >= max)
                {
                    depth++;
                    max *= BranchSize;
                    var newbr = GetNewBranch();
                    newbr.br[0] = br;
                    newbr.value++;
                    br = newbr;
                }
                path    = new VariableBranch[depth];
                pathInd = new int[depth];
            }

            var d       = depth;
            var vb      = br;
            var subSize = max;


            while (d > 0)
            {
                subSize /= BranchSize;
                var no = ind / subSize;
                ind -= no * subSize;
                if (vb.br[no] == null)
                {
                    vb.br[no] = GetNewBranch(); vb.value++;
                }
                d--;
                path[d]    = vb;
                pathInd[d] = no;
                vb         = vb.br[no];
            }

            if (vb.br[ind] == null)
            {
                vb.br[ind] = GetNewFruit();
                vb.value  += 1;
            }

            var fvb = vb.br[ind];

            if (val)
            {
                fvb.value |= 0x00000001 << bitNo;
            }
            else
            {
                fvb.value &= ~(0x00000001 << bitNo);
            }

            if (fvb.value == 0)
            {
                DiscardFruit(vb, ind);
            }

            while (d < depth)
            {
                if (vb.value > 0)
                {
                    return;
                }
                vb = path[d];
                DiscardBranch(vb, pathInd[d]);
                d++;
            }

            TryReduceDepth();
        }
Esempio n. 14
0
        private void Set(int ind, int val)
        {
            //Debug.Log("Setting "+ind+" to "+val);

            if (ind >= max)
            {
                if (val == 0)
                {
                    return;
                }
                while (ind >= max)
                {
                    depth++;
                    max *= BranchSize;
                    var newBranch = GetNewBranch();
                    //newbr.br = new VariableBranch[branchSize];
                    newBranch.br[0] = br;
                    newBranch.value++;
                    br = newBranch;
                }
                path    = new VariableBranch[depth];
                pathInd = new int[depth];
            }

            var d       = depth;
            var vb      = br;
            var subSize = max;

            if (val != 0)
            {
                while (d > 0)
                {
                    subSize /= BranchSize;
                    var no = ind / subSize;
                    ind -= no * subSize;
                    if (vb.br[no] == null)
                    {
                        vb.br[no] = GetNewBranch(); vb.value++;
                    }
                    d--;
                    vb = vb.br[no];
                }

                if (vb.br[ind] == null)
                {
                    vb.br[ind] = GetNewFruit();
                    vb.value  += 1;
                }


                vb.br[ind].value = val;
            }
            else
            {
                while (d > 0)
                {
                    subSize /= BranchSize;
                    var no = ind / subSize;
                    ind -= no * subSize;
                    if (vb.br[no] == null)
                    {
                        return;
                    }
                    d--;
                    path[d]    = vb;
                    pathInd[d] = no;
                    vb         = vb.br[no];
                }

                if (vb.br[ind] == null)
                {
                    return;
                }

                DiscardFruit(vb, ind);

                while (d < depth)
                {
                    if (vb.value > 0)
                    {
                        return;
                    }
                    vb = path[d];
                    DiscardBranch(vb, pathInd[d]);
                    d++;
                }

                TryReduceDepth();
            }
        }
Esempio n. 15
0
 protected CountlessBase()
 {
     max = BranchSize;
     br  = GetNewBranch();
 }
Esempio n. 16
0
        private void Set(int ind, List<T> obj)
        {
            if (ind >= max)
            {
                if (obj == null)
                    return;
                while (ind >= max)
                {
                    depth++;
                    max *= BranchSize;
                    var newBranch = GetNewBranch();
                    //newbr.br = new VariableBranch[branchSize];
                    newBranch.br[0] = br;
                    newBranch.value++;
                    br = newBranch;
                }
                path = new VariableBranch[depth];
                pathInd = new int[depth];
            }

            var d = depth;
            var vb = br;
            var subSize = max;

            if (obj != null)
            {
                while (d > 0)
                {
                    subSize /= BranchSize;
                    var no = ind / subSize;
                    ind -= no * subSize;
                    if (vb.br[no] == null) { vb.br[no] = GetNewBranch(); vb.value++; }
                    d--;
                    vb = vb.br[no];
                }

                if (vb.br[ind] == null)
                {
                    vb.br[ind] = GetNewFruit();
                    vb.value += 1;

                    var cnt = _objs.Length;
                    while ((_firstFreeObj < cnt) && (_objs[_firstFreeObj] != null)) _firstFreeObj++;
                    if (_firstFreeObj >= cnt)
                        Expand(ref _objs, BranchSize);

                    _objs[_firstFreeObj] = obj;
                    vb.br[ind].value = _firstFreeObj;
                }
                else
                    _objs[vb.br[ind].value] = obj;

            }
            else
            {
                while (d > 0)
                {
                    subSize /= BranchSize;
                    var no = ind / subSize;
                    ind -= no * subSize;
                    if (vb.br[no] == null) return;
                    d--;
                    path[d] = vb;
                    pathInd[d] = no;
                    vb = vb.br[no];
                }

                if (vb.br[ind] == null)
                    return;


                var ar = vb.br[ind].value;

                _objs[ar] = default(List<T>);
                _firstFreeObj = Mathf.Min(_firstFreeObj, ar);

                DiscardFruit(vb, ind);

                while (d < depth)
                {
                    if (vb.value > 0)
                        return;
                    vb = path[d];
                    DiscardBranch(vb, pathInd[d]);
                    d++;
                }

                TryReduceDepth();

            }
        }