Esempio n. 1
0
        public virtual (Slice Begin, Slice End) ToRange(Slice prefix, ITuple items)
        {
            var writer = new SliceWriter(prefix, 16);

            PackKey(ref writer, items);
            return(ToRange(writer.ToSlice()));
        }
Esempio n. 2
0
        public virtual FdbKeyRange ToRange(Slice prefix, IFdbTuple items)
        {
            var writer = new SliceWriter(prefix, 16);

            PackKey(ref writer, items);
            return(ToRange(writer.ToSlice()));
        }
Esempio n. 3
0
        public static Slice[] Convert(SliceWriter writer, [NotNull, ItemNotNull] IEnumerable <TValue> values, Handler handler, TState state)
        {
            Contract.Requires(values != null && handler != null);

            //Note on performance:
            // - we will reuse the same buffer for each temp key, and copy them into a slice buffer
            // - doing it this way adds a memory copy (writer => buffer) but reduce the number of byte[] allocations (and reduce the GC overhead)

            int start = writer.Position;

            var buffer = new SliceBuffer();

            var coll = values as ICollection <TValue>;

            if (coll != null)
            {             // pre-allocate the final array with the correct size
                var res = new Slice[coll.Count];
                int p   = 0;
                foreach (var tuple in coll)
                {
                    // reset position to just after the subspace prefix
                    writer.Position = start;

                    handler(ref writer, tuple, state);

                    // copy full key in the buffer
                    res[p++] = buffer.Intern(writer.ToSlice());
                }
                Contract.Assert(p == res.Length);
                return(res);
            }
            else
            {             // we won't now the array size until the end...
                var res = new List <Slice>();
                foreach (var tuple in values)
                {
                    // reset position to just after the subspace prefix
                    writer.Position = start;

                    handler(ref writer, tuple, state);

                    // copy full key in the buffer
                    res.Add(buffer.Intern(writer.ToSlice()));
                }
                return(res.ToArray());
            }
        }
		internal static Slice Pack([NotNull] CompressedWord[] words, int size, int highest)
		{
			Contract.Requires(size >= 0 && size <= words.Length);

			if (size == 0)
			{ // empty bitmap
				return Slice.Empty;
			}

			var writer = new SliceWriter(checked((size + 1) << 2));
			writer.WriteFixed32(CompressedWord.MakeHeader(highest));
			for (int i = 0; i < size; i++)
			{
				writer.WriteFixed32(words[i].RawValue);
			}
			return writer.ToSlice();
		}
		private void InitializeDirectory(IFdbTransaction trans)
		{
			// Set the version key
			var writer = new SliceWriter(3 * 4);
			writer.WriteFixed32((uint)LayerVersion.Major);
			writer.WriteFixed32((uint)LayerVersion.Minor);
			writer.WriteFixed32((uint)LayerVersion.Build);
			trans.Set(this.RootNode.Pack(VersionKey), writer.ToSlice());
		}
		private void InitializeDirectory([NotNull] IFdbTransaction trans)
		{
			Contract.Requires(trans != null);

			// Set the version key
			var writer = new SliceWriter(3 * 4);
			writer.WriteFixed32((uint)LayerVersion.Major);
			writer.WriteFixed32((uint)LayerVersion.Minor);
			writer.WriteFixed32((uint)LayerVersion.Build);
			trans.Set(this.RootNode.Keys.Encode(VersionKey), writer.ToSlice());
		}