Example #1
0
        public IEnumerable <SeekResult> SeekForwardFrom(TableSchema.SchemaIndexDef index, Slice value, bool startsWith = false)
        {
            var tree = GetTree(index);

            using (var it = tree.Iterate(false))
            {
                if (startsWith)
                {
                    it.RequiredPrefix = value.Clone(_tx.Allocator);
                }

                if (it.Seek(value) == false)
                {
                    yield break;
                }

                do
                {
                    yield return(new SeekResult
                    {
                        Key = it.CurrentKey,
                        Results = GetSecondaryIndexForValue(tree, it.CurrentKey.Clone(_tx.Allocator))
                    });
                } while (it.MoveNext());
            }
        }
Example #2
0
        public Table OpenTable(TableSchema schema, Slice name)
        {
            if (_tables == null)
            {
                _tables = new Dictionary <Slice, Table>(SliceStructComparer.Instance);
            }

            Table value;

            if (_tables.TryGetValue(name, out value))
            {
                return(value);
            }

            var clonedName = name.Clone(Allocator);

            var tableTree = ReadTree(clonedName, RootObjectType.Table);

            if (tableTree == null)
            {
                return(null);
            }


            value = new Table(schema, clonedName, this, tableTree, schema.TableType);
            _tables[clonedName] = value;
            return(value);
        }
Example #3
0
 internal void AddMultiValueTree(Tree tree, Slice key, Tree mvTree)
 {
     if (_multiValueTrees == null)
     {
         _multiValueTrees = new Dictionary <Tuple <Tree, Slice>, Tree>(new TreeAndSliceComparer());
     }
     mvTree.IsMultiValueTree = true;
     _multiValueTrees.Add(Tuple.Create(tree, key.Clone(_lowLevelTransaction.Allocator, ByteStringType.Immutable)), mvTree);
 }
Example #4
0
 internal void AddMultiValueTree(Tree tree, Slice key, Tree mvTree)
 {
     if (_multiValueTrees == null)
     {
         _multiValueTrees = new Dictionary <Tuple <Tree, Slice>, Tree>(new TreeAndSliceComparer());
     }
     mvTree.IsMultiValueTree = true;
     _multiValueTrees.Add(Tuple.Create(tree, key.Clone()), mvTree);
 }
Example #5
0
        private FixedSizeTree GetFixedSizeTree(Tree parent, Slice name, ushort valSize)
        {
            Dictionary <Slice, FixedSizeTree> cache;

            var parentName = Slice.From(_tx.Allocator, parent.Name ?? Constants.RootTreeName, ByteStringType.Immutable);

            if (_fixedSizeTreeCache.TryGetValue(parentName, out cache) == false)
            {
                _fixedSizeTreeCache[parentName] = cache = new Dictionary <Slice, FixedSizeTree>(SliceComparer.Instance);
            }

            FixedSizeTree tree;

            if (cache.TryGetValue(name, out tree) == false)
            {
                var treeName      = name.Clone(_tx.Allocator);
                var fixedSizeTree = new FixedSizeTree(_tx.LowLevelTransaction, parent, treeName, valSize);
                return(cache[fixedSizeTree.Name] = fixedSizeTree);
            }

            return(tree);
        }
Example #6
0
        public IEnumerable <TableValueReader> SeekByPrimaryKey(Slice value, bool startsWith = false)
        {
            var pk   = _schema.Key;
            var tree = GetTree(pk);

            using (var it = tree.Iterate(false))
            {
                if (startsWith)
                {
                    it.RequiredPrefix = value.Clone(_tx.Allocator);
                }

                if (it.Seek(value) == false)
                {
                    yield break;
                }

                do
                {
                    yield return(GetTableValueReader(it));
                }while (it.MoveNext());
            }
        }
Example #7
0
 public void SetRequiredPrefix(Slice prefix)
 {
     _requiredPrefix    = prefix.Clone(_tx.Allocator); // make sure the prefix slice won't become invalid during iterator usage
     _requireValidation = _maxKey.HasValue || _requiredPrefix.HasValue;
 }
Example #8
0
 internal void AddMultiValueTree(Tree tree, Slice key, Tree mvTree)
 {
     if (_multiValueTrees == null)
         _multiValueTrees = new Dictionary<Tuple<Tree, Slice>, Tree>(new TreeAndSliceComparer());
     mvTree.IsMultiValueTree = true;
     _multiValueTrees.Add(Tuple.Create(tree, key.Clone()), mvTree);
 }
 public void AddKey(Slice key)
 {
     Slice k = key.Clone();
     start_.Add(keys_.Length);
     keys_ += k.Data.GetString(k.Size);
 }