Ejemplo n.º 1
0
 /// <inheritdoc />
 public void ModifiedIndex(MemoryIndex index)
 {
     if (!(index is TemporaryIndex))
     {
         indexChanges.Add(index);
     }
 }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public override void SetArray(MemoryIndex index, AssociativeArray arrayValue)
        {
            IIndexDefinition data;

            if (!indexDefinitions.TryGetValue(index, out data))
            {
                data = new CopyIndexDefinition();
            }

            IIndexDefinitionBuilder builder = data.Builder(this);

            builder.SetArray(arrayValue);

            indexDefinitions[index] = builder.Build(this);

            IArrayDescriptor descriptor;

            if (TryGetDescriptor(arrayValue, out descriptor))
            {
                if (descriptor.ParentIndex != null)
                {
                    GetWriteableStackContext(descriptor.ParentIndex.CallLevel).WriteableArrays.Remove(arrayValue);
                }
            }
            GetWriteableStackContext(index.CallLevel).WriteableArrays.Add(arrayValue);
        }
Ejemplo n.º 3
0
        private bool compareData(MemoryIndex index)
        {
            MemoryEntry newEntry = null;

            if (!newData.Readonly.TryGetMemoryEntry(index, out newEntry))
            {
                newEntry = snapshot.EmptyEntry;
            }

            MemoryEntry oldEntry = null;

            if (!oldData.Readonly.TryGetMemoryEntry(index, out oldEntry))
            {
                oldEntry = snapshot.EmptyEntry;
            }

            if (ValueUtils.CompareMemoryEntries(newEntry, oldEntry))
            {
                return(true);
            }
            else if (newEntry.Count > simplifyLimit)
            {
                MemoryEntry simplifiedEntry = assistant.Simplify(newEntry);
                MemoryEntry entry           = setNewMemoryEntry(index, newEntry, simplifiedEntry);

                return(ValueUtils.CompareMemoryEntries(entry, oldEntry));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Stores given collection as the source of indexes and adds its unknown index into unknown operation.
        /// Also gets all indexes from the source collection and inserts it into target collection.
        ///
        /// This method is for the first phase of anaysis.
        /// </summary>
        /// <param name="sourceSnapshot">The source snapshot.</param>
        /// <param name="sourceIndex">Index of the source.</param>
        /// <param name="sourceContainer">The source container.</param>
        public void CollectIndexes(
            Snapshot sourceSnapshot,
            MemoryIndex sourceIndex,
            IReadonlyIndexContainer sourceContainer)
        {
            sources.Add(new Tuple <IReadonlyIndexContainer, Snapshot>(sourceContainer, sourceSnapshot));

            unknownOperation.Add(sourceContainer.UnknownIndex, sourceSnapshot);

            bool indexEquals = targetIndex.Equals(sourceIndex);

            foreach (var index in sourceContainer.Indexes)
            {
                MemoryIndex containerIndex;
                if (targetContainer.TryGetIndex(index.Key, out containerIndex))
                {
                    if (containerIndex == null && indexEquals)
                    {
                        writeableTargetContainer.AddIndex(index.Key, index.Value);
                        undefinedIndexes.Remove(index.Key);
                    }
                }
                else if (indexEquals)
                {
                    writeableTargetContainer.AddIndex(index.Key, index.Value);
                }
                else
                {
                    writeableTargetContainer.AddIndex(index.Key, null);
                    undefinedIndexes.Add(index.Key);
                }
            }
        }
Ejemplo n.º 5
0
                private int _j; // index into sortedFields

                #endregion Fields

                #region Constructors

                public MemoryTermEnum(MemoryIndex index, MemoryIndexReader reader, int ix, int jx)
                {
                    _index = index;
                    _reader = reader;
                    _i = ix; // index into info.sortedTerms
                    _j = jx; // index into sortedFields
                }
Ejemplo n.º 6
0
        public override LocationCollectorNode CreateMemoryIndexAnyChild(MemoryIndex unknownIndex)
        {
            UnknownIndexCollectorNode node = new UnknownIndexCollectorNode(unknownIndex);

            addAnyChild(node);
            return(node);
        }
Ejemplo n.º 7
0
        public void CollectAliases(MemoryIndex index, Snapshot snapshot, bool isMust)
        {
            if (References == null)
            {
                References = new ReferenceCollector();
            }

            IMemoryAlias aliases;

            if (snapshot.Structure.Readonly.TryGetAliases(index, out aliases))
            {
                References.CollectMay(aliases.MayAliases);

                if (isMust)
                {
                    References.CollectMust(aliases.MustAliases);
                }
                else
                {
                    References.CollectMay(aliases.MustAliases);
                }
            }

            if (isMust)
            {
                References.AddMustAlias(index);
            }
            else
            {
                References.AddMayAlias(index);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds the aliases to given index. Alias entry of the given alias indexes are not changed.
        /// If given memory index contains no aliases new alias entry is created.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="mustAlias">The must alias.</param>
        /// <param name="mayAlias">The may alias.</param>
        public void AddAlias(MemoryIndex index, MemoryIndex mustAlias, MemoryIndex mayAlias)
        {
            IMemoryAliasBuilder alias;

            if (!memoryAliases.TryGetValue(index, out alias))
            {
                alias = Factories.StructuralContainersFactories.MemoryAliasFactory.CreateMemoryAlias(writeableStrucure, index).Builder(writeableStrucure);
            }

            if (mustAlias != null)
            {
                alias.MustAliases.Add(mustAlias);

                if (alias.MayAliases.Contains(mustAlias))
                {
                    alias.MayAliases.Remove(mustAlias);
                }
            }

            if (mayAlias != null && !alias.MustAliases.Contains(mayAlias))
            {
                alias.MayAliases.Add(mayAlias);
            }

            memoryAliases[index] = alias;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CopyIndexContainer"/> class.
        ///
        /// Content of given container is copied to the new container.
        /// </summary>
        /// <param name="container">The container.</param>
        public CopyIndexContainer(IReadonlyIndexContainer container)
        {
            unknownIndex = container.UnknownIndex;

            indexes = new Dictionary <string, MemoryIndex>();
            CollectionMemoryUtils.AddAll(indexes, container.Indexes);
        }
Ejemplo n.º 10
0
        /// <inheritdoc />
        public override void SetArray(MemoryIndex index, AssociativeArray arrayValue)
        {
            IIndexDefinition data;

            if (!indexDefinitions.TryGetValue(index, out data))
            {
                data = Factories.StructuralContainersFactories.IndexDefinitionFactory.CreateIndexDefinition(this);
            }

            IIndexDefinitionBuilder builder = data.Builder(this);

            builder.SetArray(arrayValue);

            indexDefinitions[index] = builder.Build(this);
            changeTracker.ModifiedIndex(index);

            IArrayDescriptor descriptor;

            if (TryGetDescriptor(arrayValue, out descriptor))
            {
                if (descriptor.ParentIndex != null)
                {
                    GetWriteableStackContext(descriptor.ParentIndex.CallLevel).WriteableArrays.Remove(arrayValue);
                }
            }
            GetWriteableStackContext(index.CallLevel).WriteableArrays.Add(arrayValue);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds the aliases to given index. Alias entry of the given alias indexes are not changed.
        /// If given memory index contains no aliases new alias entry is created.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="mustAliases">The must aliases.</param>
        /// <param name="mayAliases">The may aliases.</param>
        public void AddAliases(MemoryIndex index, IEnumerable <MemoryIndex> mustAliases, IEnumerable <MemoryIndex> mayAliases)
        {
            IMemoryAliasBuilder alias;

            if (!memoryAliases.TryGetValue(index, out alias))
            {
                alias = Factories.StructuralContainersFactories.MemoryAliasFactory.CreateMemoryAlias(writeableStrucure, index).Builder(writeableStrucure);
            }

            if (mustAliases != null)
            {
                alias.MustAliases.AddAll(mustAliases);
            }
            if (mayAliases != null)
            {
                alias.MayAliases.AddAll(mayAliases);
            }

            foreach (MemoryIndex mustIndex in alias.MustAliases)
            {
                if (alias.MayAliases.Contains(mustIndex))
                {
                    alias.MayAliases.Remove(mustIndex);
                }
            }

            memoryAliases[index] = alias;
        }
Ejemplo n.º 12
0
        public MemoryIndexTest()
        {
            Snapshot snapshot = new Snapshot();

            snapshot.StartTransaction();
            ObjectValue object1 = snapshot.CreateObject(null);
            ObjectValue object2 = snapshot.CreateObject(null);

            snapshot.CommitTransaction();

            variableA         = VariableIndex.Create("a", 0);
            variableA2        = VariableIndex.Create("a", 0);
            variableB         = VariableIndex.Create("b", 0);
            undefinedVariable = VariableIndex.CreateUnknown(0);

            fieldA  = ObjectIndex.Create(object1, "a");
            fieldA2 = ObjectIndex.Create(object1, "a");
            fieldB  = ObjectIndex.Create(object1, "b");
            fieldInDifferentTree = ObjectIndex.Create(object2, "a");
            undefinedField       = ObjectIndex.CreateUnknown(object1);

            indexA  = variableA.CreateIndex("a");
            indexA2 = variableA.CreateIndex("a");
            indexB  = variableA.CreateIndex("b");
            indexInDifferentTree = variableB.CreateIndex("a");
            undefinedIndex       = variableA.CreateUnknownIndex();

            doubleIndex = indexA.CreateIndex("1");

            indexInField = fieldA.CreateIndex("1");
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="LazyCopyIndexContainer" /> class.
        /// Content of given container is copied to the new container.
        /// </summary>
        /// <param name="container">The container.</param>
        public LazyCopyIndexContainer(LazyCopyIndexContainer container)
        {
            unknownIndex = container.UnknownIndex;

            indexes = container.indexes;
            copied  = false;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Tests the and create implicit object.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="values">The values.</param>
        private void testAndCreateImplicitObject(MemoryCollectorNode node, HashSet <Value> values)
        {
            if (node.HasNewImplicitObject)
            {
                ObjectValue value = Snapshot.MemoryAssistant.CreateImplicitObject();
                values.Add(value);

                IObjectValueContainerBuilder objectValues = Structure.GetObjects(node.TargetIndex).Builder(Structure);
                objectValues.Add(value);
                Structure.SetObjects(node.TargetIndex, objectValues.Build(Structure));

                IObjectDescriptor        oldDescriptor = Structure.GetDescriptor(value);
                IObjectDescriptorBuilder builder       = oldDescriptor.Builder(Structure);

                foreach (var newChild in node.ImplicitObjectNode.UndefinedChildren)
                {
                    string childName = newChild.Item1;
                    MemoryCollectorNode childNode = newChild.Item2;

                    MemoryIndex index = ObjectIndex.Create(value, childName);
                    childNode.TargetIndex = index;

                    builder.AddIndex(childName, index);
                }

                IObjectDescriptor newDescriptor = builder.Build(Structure);
                Structure.SetDescriptor(value, newDescriptor);

                enqueueChildNodes(node.ImplicitObjectNode);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates the memory index child.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="memoryIndex">Index of the memory.</param>
        /// <returns>Child node</returns>
        public virtual LocationCollectorNode CreateMemoryIndexChild(string name, MemoryIndex memoryIndex)
        {
            MemoryIndexCollectorNode node = new MemoryIndexCollectorNode(memoryIndex);

            addChild(node, name);
            return(node);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Deletes the array.
        /// </summary>
        /// <param name="targetIndex">Index of the target.</param>
        /// <param name="targetArray">The target array.</param>
        public void DeleteArray(MemoryIndex targetIndex, AssociativeArray targetArray)
        {
            IArrayDescriptor targetArrayDescriptor = targetStructure.GetDescriptor(targetArray);

            foreach (var index in targetArrayDescriptor.Indexes)
            {
                // Enqueue delete operation for every child index
                MemoryIndex    childIndex     = index.Value;
                MergeOperation childOperation = new MergeOperation();
                childOperation.SetTargetIndex(childIndex);
                childOperation.SetDeleteOperation();
                operationQueue.AddLast(childOperation);
            }

            // Enqueue delete operation for unknown index
            MergeOperation unknownOperation = new MergeOperation();

            unknownOperation.SetTargetIndex(targetArrayDescriptor.UnknownIndex);
            unknownOperation.SetUndefined();
            unknownOperation.SetDeleteOperation();
            operationQueue.AddLast(unknownOperation);

            // Deletes array from structure
            writeableTargetStructure.RemoveArray(targetIndex, targetArray);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Processes the source array.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="arrayValue">The array value.</param>
        /// <param name="values">The values.</param>
        private void processSourceArray(MemoryCollectorNode node, AssociativeArray arrayValue, ICollection <Value> values)
        {
            if (arrayValue != null)
            {
                IArrayDescriptor sourceArray = Structure.GetDescriptor(arrayValue);

                if (node.AnyChildNode == null)
                {
                    node.CreateMemoryIndexAnyChild(sourceArray.UnknownIndex);
                }

                foreach (var item in sourceArray.Indexes)
                {
                    string      name  = item.Key;
                    MemoryIndex index = item.Value;

                    if (!node.NamedChildNodes.ContainsKey(name))
                    {
                        LocationCollectorNode newChild = node.CreateMemoryIndexChildFromAny(name, sourceArray.UnknownIndex);
                        newChild.IsMust = node.IsMust;
                    }
                }

                createArray(node, values);
            }
            else
            {
                testAndCreateImplicitArray(node, values);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Merges the memory index data.
        /// </summary>
        /// <param name="targetIndex">Index of the target.</param>
        private void mergeMemoryIndexData(MemoryIndex targetIndex)
        {
            IIndexDefinition definition;

            if (targetStructure.TryGetIndexDefinition(targetIndex, out definition))
            {
                bool valuesAlwaysDefined = collectValues(targetIndex);

                if (definition.Array != null)
                {
                    values.Add(definition.Array);
                }
                if (!valuesAlwaysDefined)
                {
                    values.Add(targetSnapshot.UndefinedValue);
                }

                MemoryEntry entry = targetSnapshot.CreateMemoryEntry(values);
                writeableTargetData.SetMemoryEntry(targetIndex, entry);

                values.Clear();
            }
            else
            {
                // Target index is not part of the structure - remove it
                writeableTargetData.RemoveMemoryEntry(targetIndex);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Assigns the specified collector.
        /// </summary>
        /// <param name="collector">The collector.</param>
        /// <param name="sourceIndex">Index of the source.</param>
        internal void Assign(IIndexCollector collector, MemoryIndex sourceIndex)
        {
            foreach (MemoryIndex mustIndex in collector.MustIndexes)
            {
                snapshot.DestroyMemory(mustIndex);
                CopyWithinSnapshotWorker copyWorker = new CopyWithinSnapshotWorker(snapshot, true);
                copyWorker.Copy(sourceIndex, mustIndex);
            }

            foreach (MemoryIndex mayIndex in collector.MayIndexes)
            {
                MergeWithinSnapshotWorker mergeWorker = new MergeWithinSnapshotWorker(snapshot);
                mergeWorker.MergeIndexes(mayIndex, sourceIndex);
            }

            MemoryEntry entry = SnapshotDataUtils.GetMemoryEntry(snapshot, snapshot.CurrentData.Readonly, sourceIndex);

            LocationVisitor mustVisitor = new LocationVisitor(snapshot, entry, true);

            foreach (ValueLocation location in collector.MustLocation)
            {
                location.Accept(mustVisitor);
            }

            LocationVisitor mayVisitor = new LocationVisitor(snapshot, entry, false);

            foreach (ValueLocation location in collector.MayLocaton)
            {
                location.Accept(mayVisitor);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Collects the values.
        /// </summary>
        /// <param name="targetIndex">Index of the target.</param>
        /// <returns>true if the value is always defined</returns>
        private bool collectValues(MemoryIndex targetIndex)
        {
            bool valuesAlwaysDefined = true;

            foreach (Snapshot sourceSnapshot in sourceSnapshots)
            {
                MemoryEntry sourceEntry = getSourceEntry(targetIndex, sourceSnapshot);
                if (sourceEntry != null)
                {
                    if (sourceEntry.ContainsAssociativeArray)
                    {
                        VisitMemoryEntry(sourceEntry);
                    }
                    else
                    {
                        CollectionMemoryUtils.AddAll(values, sourceEntry.PossibleValues);
                    }
                }
                else
                {
                    valuesAlwaysDefined = false;
                }
            }

            return(valuesAlwaysDefined);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Updates the aliases.
        /// </summary>
        private void updateAliases()
        {
            foreach (var item in MemoryAliases)
            {
                MemoryIndex     targetIndex = item.Key;
                MemoryAliasInfo aliasInfo   = item.Value;

                if (!aliasInfo.IsTargetOfMerge)
                {
                    IMemoryAlias currentAliases;
                    if (writeableTargetStructure.TryGetAliases(targetIndex, out currentAliases))
                    {
                        aliasInfo.Aliases.MayAliases.AddAll(currentAliases.MayAliases);
                        aliasInfo.Aliases.MustAliases.AddAll(currentAliases.MustAliases);
                    }
                }
                foreach (MemoryIndex alias in aliasInfo.RemovedAliases)
                {
                    aliasInfo.Aliases.MustAliases.Remove(alias);
                    aliasInfo.Aliases.MayAliases.Remove(alias);
                }

                writeableTargetStructure.SetAlias(targetIndex, aliasInfo.Aliases.Build(writeableTargetStructure));
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Collects the source array.
        /// </summary>
        /// <param name="targetIndex">Index of the target.</param>
        /// <param name="operation">The operation.</param>
        /// <param name="operationContext">The operation context.</param>
        /// <param name="sourceArray">The source array.</param>
        public void collectSourceArray(MemoryIndex targetIndex, MergeOperation operation, MergeOperationContext operationContext, AssociativeArray sourceArray)
        {
            // Source array
            if (sourceArray != null)
            {
                // Becomes target array when not set
                if (targetArray == null && operationContext.Index.Equals(targetIndex))
                {
                    targetArray = sourceArray;
                }
                hasArray = true;

                // Save source array to merge descriptors
                IArrayDescriptor descriptor = operationContext.SnapshotContext.SourceStructure.GetDescriptor(sourceArray);
                sourceArrays.Add(new ContainerContext(operationContext.SnapshotContext, descriptor, operationContext.OperationType));

                // Equeue all array indexes when whole subtree should be merged
                if (operationContext.OperationType == MergeOperationType.WholeSubtree)
                {
                    foreach (var index in descriptor.Indexes)
                    {
                        operation.TreeNode.GetOrCreateChild(index.Key);
                    }
                    operation.TreeNode.GetOrCreateAny();
                }
            }
            else
            {
                // Source do not contain array - at least one source is empty
                arrayAlwaysDefined = false;
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CopyMemoryAlias" /> class.
 /// </summary>
 /// <param name="associatedStructure">The associated structure.</param>
 /// <param name="memoryAlias">The memory alias.</param>
 public LazyCopyMemoryAlias(IWriteableSnapshotStructure associatedStructure, LazyCopyMemoryAlias memoryAlias)
 {
     this.sourceIndex         = memoryAlias.sourceIndex;
     this.mayAliases          = memoryAlias.mayAliases.Clone();
     this.mustAliases         = memoryAlias.mustAliases.Clone();
     this.associatedStructure = associatedStructure;
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Creates the memory index any child.
        /// </summary>
        /// <param name="unknownIndex">Index of the unknown.</param>
        /// <returns>Child node</returns>
        public virtual LocationCollectorNode CreateMemoryIndexAnyChild(MemoryIndex unknownIndex)
        {
            MemoryIndexCollectorNode node = new MemoryIndexCollectorNode(unknownIndex);

            addAnyChild(node);
            return(node);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryIndexTreeNode"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="index">The index.</param>
 public MemoryIndexTreeNode(MemoryIndexTreeNode parent = null, MemoryIndex index = null)
 {
     Index      = index;
     ParentNode = parent;
     AnyChild   = null;
     ChildNodes = new Dictionary <string, MemoryIndexTreeNode>();
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Processes single merge operation - prepares all valid values and alias informations from the source indexes.
        /// When the source indexes contains some array values prepares operation for every descendant index and merge the
        /// array into one which will be stored in the target memory entry.
        /// </summary>
        /// <param name="operation">The operation.</param>
        private void processMergeOperation(MergeOperation operation)
        {
            HashSet <Value> values = new HashSet <Value>();

            foreach (var operationData in operation.Indexes)
            {
                MemoryIndex index    = operationData.Item1;
                Snapshot    snapshot = operationData.Item2;

                MemoryEntry entry = SnapshotDataUtils.GetMemoryEntry(snapshot, snapshot.Infos.Readonly, index);
                CollectionMemoryUtils.AddAll(values, entry.PossibleValues);
            }

            if (Structure.Readonly.HasArray(operation.TargetIndex))
            {
                mergeArrays(operation);
            }

            if (operation.IsUndefined)
            {
                values.Add(targetSnapshot.UndefinedValue);
            }

            Infos.Writeable.SetMemoryEntry(operation.TargetIndex, targetSnapshot.CreateMemoryEntry(values));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Prepares operation for every descendant index of target array.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <returns>Array where the input arrays is merged into.</returns>
        private void mergeArrays(MergeOperation operation)
        {
            AssociativeArray    targetArray      = Structure.Readonly.GetArray(operation.TargetIndex);
            IArrayDescriptor    targetDescriptor = Structure.Readonly.GetDescriptor(targetArray);
            ContainerOperations collectIndexes   = new ContainerOperations(this, targetDescriptor, operation.TargetIndex, targetDescriptor.UnknownIndex);

            foreach (var operationData in operation.Indexes)
            {
                MemoryIndex index    = operationData.Item1;
                Snapshot    snapshot = operationData.Item2;

                AssociativeArray arrayValue;
                if (snapshot.Structure.Readonly.TryGetArray(index, out arrayValue))
                {
                    IArrayDescriptor descriptor = snapshot.Structure.Readonly.GetDescriptor(arrayValue);
                    collectIndexes.AddContainer(descriptor, snapshot);
                }
                else
                {
                    collectIndexes.SetUndefined();
                }
            }

            collectIndexes.MergeContainers();
        }
Ejemplo n.º 28
0
        private void createAliasesRepresentation(Snapshot snapshot, StringBuilder result)
        {
            foreach (var item in snapshot.Structure.Readonly.IndexDefinitions)
            {
                var aliases = item.Value.Aliases;
                if (aliases != null && (aliases.MayAliases.Count > 0 || aliases.MustAliases.Count > 0))
                {
                    MemoryIndex index = item.Key;
                    result.AppendFormat("{0}: {{ ", index);

                    result.Append(" MUST: ");
                    foreach (var alias in aliases.MustAliases)
                    {
                        result.Append(alias);
                        result.Append(", ");
                    }
                    result.Length -= 2;

                    result.Append(" | MAY: ");
                    foreach (var alias in aliases.MayAliases)
                    {
                        result.Append(alias);
                        result.Append(", ");
                    }
                    result.Length -= 2;
                    result.AppendLine(" }");
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Sets the collected aliases to specified index in the given spanshot.
        /// </summary>
        /// <param name="memoryIndex">Index of the memory.</param>
        /// <param name="snapshot">The snapshot.</param>
        /// <param name="isMust">if set to <c>true</c> uses must and may aliases otherwise all must aliases are invalidated.</param>
        internal void SetAliases(MemoryIndex memoryIndex, IReferenceHolder snapshot, bool isMust)
        {
            if (allReferences.Count == 0)
            {
                return;
            }

            if (!isMust)
            {
                InvalidateMust();
            }

            HashSet <MemoryIndex> mayReferences = new HashSet <MemoryIndex>();

            CopyMayReferencesTo(mayReferences);

            foreach (MemoryIndex mustAlias in mustReferences)
            {
                snapshot.AddAlias(mustAlias, memoryIndex, null);
            }

            foreach (MemoryIndex mayAlias in mayReferences)
            {
                snapshot.AddAlias(mayAlias, null, memoryIndex);
            }

            snapshot.AddAliases(memoryIndex, mustReferences, mayReferences);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Processes the index - traverse thru array or sets path to undefined.
        /// </summary>
        /// <param name="parentIndex">Index of the parent.</param>
        /// <param name="indexSegment">The index segment.</param>
        /// <param name="visitor">The visitor to process scalar values.</param>
        private void processIndex(MemoryIndex parentIndex, IndexPathSegment indexSegment, ProcessValueAsLocationVisitor visitor)
        {
            MemoryEntry entry;

            if (snapshot.Data.Readonly.TryGetMemoryEntry(parentIndex, out entry))
            {
                bool             processOtherValues = false;
                AssociativeArray arrayValue;
                if (snapshot.Structure.Readonly.TryGetArray(parentIndex, out arrayValue))
                {
                    IArrayDescriptor descriptor = snapshot.Structure.Readonly.GetDescriptor(arrayValue);
                    process(indexSegment, descriptor);

                    processOtherValues = entry.Count > 1;
                }
                else if (entry.Count > 0)
                {
                    processOtherValues = true;
                }
                else
                {
                    IsDefined = false;
                }

                if (processOtherValues)
                {
                    visitor.ProcessValues(parentIndex, entry.PossibleValues, true);
                }
            }
            else
            {
                IsDefined = false;
            }
        }
Ejemplo n.º 31
0
        private static void DumpIndex <TKey, TVal>(string label, MemoryIndex <TKey> index, Func <TKey, int, TVal> orderBy, IComparer <TVal> comparer = null, bool heatMaps = false)
        {
            comparer = comparer ?? Comparer <TVal> .Default;

            int  total       = index.Statistics.Values.Sum();
            long totalLegacy = 0;

            int[]  map = new int[100];
            double r   = (double)(map.Length - 1) / total;

            Console.WriteLine("__{0}__", label);
            Console.WriteLine("| Indexed Value           |  Count | Total % | Words |  Lit%  | 1-Bits |  Word% |   Bitmap | ratio % |   Legacy  | ratio % |" + (heatMaps ? " HeatMap |" : ""));
            Console.WriteLine("|:------------------------|-------:|--------:|------:|-------:|-------:|-------:|---------:|--------:|----------:|--------:|" + (heatMaps ? ":-----------------------------------------------------------------------|" : ""));
            foreach (var kv in index.Values.OrderBy((kv) => orderBy(kv.Key, index.Count(kv.Key)), comparer))
            {
                var t  = STuple.Create(kv.Key);
                var tk = t.ToSlice();

                int    bits, words, literals, fillers;
                double ratio;
                kv.Value.GetStatistics(out bits, out words, out literals, out fillers, out ratio);

                long legacyIndexSize = 0;                 // size estimate of a regular FDB index (..., "Value", GUID) = ""
                Array.Clear(map, 0, map.Length);
                foreach (var p in kv.Value.GetView())
                {
                    map[(int)(r * p)]++;
                    legacyIndexSize += 3 + tk.Count + 17;
                }
                totalLegacy += legacyIndexSize;

                int bytes = kv.Value.ToSlice().Count;

                Console.WriteLine(string.Format(
                                      CultureInfo.InvariantCulture,
                                      "| {0,-24}| {1,6:N0} | {2,6:N2}% | {3,5:N0} | {4,5:N1}% | {5,6:N0} | {6,6:N2} | {7,8:N0} | {8,6:N2}% | {9,9:N0} | {10,6:N2}% |" + (heatMaps ? " `{11}` |" : ""),
                                      /*0*/ t,
                                      /*1*/ index.Count(kv.Key),
                                      /*2*/ 100.0 * index.Frequency(kv.Key),
                                      /*3*/ words,
                                      /*4*/ (100.0 * literals) / words,
                                      /*5*/ bits,
                                      /*6*/ 1.0 * bits / words,
                                      /*7*/ bytes,
                                      /*8*/ 100.0 * ratio,
                                      /*9*/ legacyIndexSize,
                                      /*A*/ (100.0 * bytes) / legacyIndexSize,
                                      /*B*/ heatMaps ? MakeHeatMap(map) : ""
                                      ));
            }

            Console.WriteLine(string.Format(
                                  CultureInfo.InvariantCulture,
                                  "> {0:N0} distinct value(s), {1:N0} document(s), {2:N0} bitmap bytes, {3:N0} legacy bytes",
                                  index.Values.Count,
                                  total,
                                  index.Values.Values.Sum(x => x.ToSlice().Count),
                                  totalLegacy
                                  ));
        }
Ejemplo n.º 32
0
 public MemoryTermPositionVector(MemoryIndex index, Info info, string fieldName)
 {
     _index = index;
     _fieldName = fieldName;
     sortedTerms = info.SortedTerms;
 }
Ejemplo n.º 33
0
        /**
         * Build a randomish document for both RAMDirectory and MemoryIndex,
         * and run all the queries against it.
         */

        public void AssertAgainstRAMDirectory()
        {
            var fooField = new StringBuilder();
            var termField = new StringBuilder();

            // add up to 250 terms to field "foo"
            for (int i = 0; i < random.Next(250); i++)
            {
                fooField.Append(" ");
                fooField.Append(RandomTerm());
            }

            // add up to 250 terms to field "term"
            for (int i = 0; i < random.Next(250); i++)
            {
                termField.Append(" ");
                termField.Append(RandomTerm());
            }

            var ramdir = new RAMDirectory();
            var analyzer = RandomAnalyzer();
            var writer = new IndexWriter(ramdir, analyzer,
                                                 IndexWriter.MaxFieldLength.UNLIMITED);
            var doc = new Document();
            var field1 = new Field("foo", fooField.ToString(), Field.Store.NO, Field.Index.ANALYZED);
            var field2 = new Field("term", termField.ToString(), Field.Store.NO, Field.Index.ANALYZED);
            doc.Add(field1);
            doc.Add(field2);
            writer.AddDocument(doc);
            writer.Close();

            var memory = new MemoryIndex();
            memory.AddField("foo", fooField.ToString(), analyzer);
            memory.AddField("term", termField.ToString(), analyzer);
            AssertAllQueries(memory, ramdir, analyzer);
        }
Ejemplo n.º 34
0
        /**
         * Run all queries against both the RAMDirectory and MemoryIndex, ensuring they are the same.
         */

        public void AssertAllQueries(MemoryIndex memory, RAMDirectory ramdir, Analyzer analyzer)
        {
            var ram = new IndexSearcher(ramdir);
            var mem = memory.CreateSearcher();
            var qp = new QueryParser(Version.LUCENE_CURRENT, "foo", analyzer);

            foreach (String query in _queries)
            {
                var ramDocs = ram.Search(qp.Parse(query), 1);
                var memDocs = mem.Search(qp.Parse(query), 1);
                Assert.AreEqual(ramDocs.TotalHits, memDocs.TotalHits);
            }
        }
Ejemplo n.º 35
0
 public MemoryTermPositions(MemoryIndex index, MemoryIndexReader reader)
 {
     _index = index;
     _reader = reader;
 }