示例#1
0
        /// <summary>
        /// Read all input items and store in temp disk ordered in each container
        /// </summary>
        public void Insert(IEnumerable <KeyValuePair <BsonValue, PageAddress> > items)
        {
            // slit all items in sorted containers
            foreach (var containerItems in this.SliptValues(items, _done))
            {
                var container = new SortContainer(_pragmas.Collation, _containerSize);

                // insert segmented items inside a container - reuse same buffer slice
                container.Insert(containerItems, _order, _buffer);

                _containers.Add(container);

                // initialize container readers: if single container, do not use Stream file... only buffer memory
                if (_done.Running == false && _containers.Count == 1)
                {
                    container.InitializeReader(null, _buffer, _pragmas.UtcDate);
                }
                else
                {
                    // store in disk
                    container.Position = _disk.GetContainerPosition();

                    _disk.Write(container.Position, _buffer);

                    container.InitializeReader(_reader.Value, null, _pragmas.UtcDate);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Loop in values enumerator to return N values for a single container
        /// </summary>
        private IEnumerable <KeyValuePair <BsonValue, PageAddress> > YieldValues(IEnumerator <KeyValuePair <BsonValue, PageAddress> > source, Done done)
        {
            var size = SortContainer.GetKeyLength(source.Current.Key) + PageAddress.SIZE;

            yield return(source.Current);

            while (source.MoveNext())
            {
                var length = SortContainer.GetKeyLength(source.Current.Key) + PageAddress.SIZE;

                done.Count++;

                if (size + length > _containerSize)
                {
                    yield break;
                }

                size += length;

                yield return(source.Current);
            }

            done.Running = false;
        }