예제 #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());
            }
        }
예제 #2
0
 private Tree GetTree(TableSchema.SchemaIndexDef idx)
 {
     if (idx.IsGlobal)
     {
         return(_tx.ReadTree(idx.Name));
     }
     return(GetTree(idx.Name));
 }
예제 #3
0
        public IEnumerable <SeekResult> SeekForwardFrom(TableSchema.SchemaIndexDef index, string value, bool startsWith = false)
        {
            Slice str;

            using (Slice.From(_tx.Allocator, value, ByteStringType.Immutable, out str))
            {
                return(SeekForwardFrom(index, str, startsWith));
            }
        }
예제 #4
0
        public long DeleteForwardFrom(TableSchema.SchemaIndexDef index, Slice value, long numberOfEntriesToDelete)
        {
            if (numberOfEntriesToDelete < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfEntriesToDelete), "Number of entries should not be negative");
            }

            if (numberOfEntriesToDelete == 0)
            {
                return(0);
            }

            var toDelete = new List <long>();
            var tree     = GetTree(index);

            using (var it = tree.Iterate(false))
            {
                if (it.Seek(value) == false)
                {
                    return(0);
                }

                do
                {
                    var fst = GetFixedSizeTree(tree, it.CurrentKey.Clone(_tx.Allocator), 0);
                    using (var fstIt = fst.Iterate())
                    {
                        if (fstIt.Seek(long.MinValue) == false)
                        {
                            break;
                        }

                        do
                        {
                            toDelete.Add(fstIt.CurrentKey);
                            numberOfEntriesToDelete--;
                        }while (numberOfEntriesToDelete > 0 && fstIt.MoveNext());
                    }
                }while (numberOfEntriesToDelete > 0 && it.MoveNext());
            }

            foreach (var id in toDelete)
            {
                Delete(id);
            }
            return(toDelete.Count);
        }