Exemple #1
0
        public string NextKey(string afterThisKey)
        {
            XBucket bucket;
            string  prefix;
            string  result = null;
            bool    found  = FindBucketForPrefix(afterThisKey, out bucket, out prefix, false);

            if (found)
            {
                result = bucket.NextKey(afterThisKey);
                if (result != null)
                {
                    return(result);
                }
            }
            // otherwise look in the next bucket
            string nextprefix = this.tree.NextKey(prefix);

            if (nextprefix == null)
            {
                return(null);
            }
            byte[] databytes = this.tree[nextprefix];
            bucket = new XBucket(this);
            bucket.Load(databytes);
            if (bucket.Count() < 1)
            {
                throw new BplusTreeException("empty bucket loaded");
            }
            return(bucket.FirstKey());
        }
Exemple #2
0
        public void Set(string key, object map)
        {
            XBucket bucket;
            string  prefix;
            bool    found = FindBucketForPrefix(key, out bucket, out prefix, false);

            if (!found)
            {
                bucket = new XBucket(this);
            }
            if (!(map is byte[]))
            {
                throw new BplusTreeBadKeyValue("xBplus only accepts byte array values");
            }
            bucket.Add(key, (byte[])map);
            this.tree[prefix] = bucket.Dump();
        }
Exemple #3
0
        public bool FindBucketForPrefix(string key, out XBucket bucket, out string prefix, bool keyIsPrefix)
        {
            bucket = null;
            prefix = key;
            if (!keyIsPrefix)
            {
                prefix = PrefixForByteCount(key, this.PrefixLength);
            }
            object datathing = this.tree.Get(prefix, "");

            if (datathing is byte[])
            {
                byte[] databytes = (byte[])datathing;
                bucket = new XBucket(this);
                bucket.Load(databytes);
                if (bucket.Count() < 1)
                {
                    throw new BplusTreeException("empty bucket loaded");
                }
                return(true);
            }
            return(false); // default
        }