private void BuildSigmaScopes(int range, byte level, byte nodeTypeIndex, int nodeCounter, int clusterSize)
        {
            int parentSqrt = ScopeValue.ParentSqrt(range);

            if (levels == null)
            {
                levels = new List <vEBTreeLevel>();
            }
            if (levels.Count <= level)
            {
                levels.Add(new vEBTreeLevel());
            }
            if (levels[level].Scopes == null)
            {
                levels[level].Scopes = new List <vEBTreeNode>();
                levels[level].Scopes.Add(new vEBTreeNode());
            }
            else
            {
                levels[level].Scopes.Add(new vEBTreeNode());
            }

            levels[level].Scopes[nodeTypeIndex].NodeCounter = nodeCounter;
            levels[level].Scopes[nodeTypeIndex].NodeSize    = parentSqrt;

            if (parentSqrt > 4)
            {
                // sigmaNode
                BuildSigmaScopes(parentSqrt, (byte)(level + 1), (byte)(2 * nodeTypeIndex), nodeCounter, parentSqrt);
                // cluster
                BuildSigmaScopes(parentSqrt, (byte)(level + 1), (byte)(2 * nodeTypeIndex + 1), nodeCounter * parentSqrt, parentSqrt);
            }
        }
        private void CreateLevels(int range)
        {
            if (levels == null)
            {
                int parentSqrt = ScopeValue.ParentSqrt(size);
                BuildSigmaScopes(range, 0, 0, 1, parentSqrt);
            }

            int baseOffset = 0;

            for (int i = 1; i < levels.Count; i++)
            {
                levels[i].BaseOffset = baseOffset;
                for (int j = 0; j < levels[i].Scopes.Count - 1; j++)
                {
                    levels[i].Scopes[j].IndexOffset = baseOffset;
                    baseOffset += levels[i].Scopes[j].NodeCounter * levels[i].Scopes[j].NodeSize;
                }
            }
        }