Esempio n. 1
0
        public static VectorNode DeserializeNode(
            long vecOffset,
            long postingsOffset,
            long componentCount,
            long weight,
            long terminator,
            Stream vectorStream,
            IDistanceCalculator model)
        {
            var vector = VectorOperations.DeserializeVector(vecOffset, (int)componentCount, model.NumOfDimensions, vectorStream);
            var node   = new VectorNode(postingsOffset, vecOffset, terminator, weight, vector);

            return(node);
        }
Esempio n. 2
0
        public static VectorNode DeserializeNode(
            long vecOffset,
            long postingsOffset,
            long componentCount,
            long weight,
            long terminator,
            Stream vectorStream,
            IVectorSpaceConfig model)
        {
            var vector = VectorOperations.DeserializeVector(vecOffset, (int)componentCount, model.VectorWidth, vectorStream);
            var node   = new VectorNode(postingsOffset, vecOffset, terminator, weight, vector);

            return(node);
        }
Esempio n. 3
0
        /// <summary>
        /// Persist tree to disk.
        /// </summary>
        /// <param name="node">Tree to perist.</param>
        /// <param name="indexStream">stream to perist tree into</param>
        /// <param name="vectorStream">stream to persist vectors in</param>
        /// <param name="postingsStream">optional stream to persist any posting references into</param>
        /// <returns></returns>
        public static (long offset, long length) SerializeTree(
            VectorNode node,
            Stream indexStream,
            Stream vectorStream,
            Stream postingsStream = null)
        {
            var stack  = new Stack <VectorNode>();
            var offset = indexStream.Position;
            var length = 0;

            if (node.ComponentCount == 0)
            {
                node = node.Right;
            }

            while (node != null)
            {
                if (node.PostingsOffset == -1 && postingsStream != null)
                {
                    SerializePostings(node, postingsStream);
                }

                node.VectorOffset = VectorOperations.SerializeVector(node.Vector, vectorStream);

                SerializeNode(node, indexStream);

                length += VectorNode.BlockSize;

                if (node.Right != null)
                {
                    stack.Push(node.Right);
                }

                node = node.Left;

                if (node == null && stack.Count > 0)
                {
                    node = stack.Pop();
                }
            }

            return(offset, length);
        }