Example #1
0
        /// <summary>
        /// Builds the initial list from the nodes signature indexes.
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        private static PossibleSignatures BuildInitialList(IEnumerable <int> list)
        {
            var linkedList = new PossibleSignatures();

            foreach (var index in list)
            {
                linkedList.Add(new PossibleSignature(index, 1));
            }
            return(linkedList);
        }
Example #2
0
        private int GetClosestSignaturesForNode(
            int[] signatureIndexList,
            PossibleSignatures linkedList,
            int maxCount, int iteration)
        {
            // If there is point adding any new signature indexes set the
            // threshold reached indicator. New signatures won't be added
            // and ones with counts lower than maxcount will be removed.
            var thresholdReached = Nodes.Count - iteration < maxCount;
            var current          = linkedList.First;
            int signatureIndex   = 0;

            while (signatureIndex < signatureIndexList.Length &&
                   current != null)
            {
                if (current.RankedSignatureIndex > signatureIndexList[signatureIndex])
                {
                    // The base list is higher than the target list. Add the element
                    // from the target list and move to the next element in each.
                    if (thresholdReached == false)
                    {
                        linkedList.AddBefore(
                            current,
                            new PossibleSignature(signatureIndexList[signatureIndex], 1));
                    }
                    signatureIndex++;
                }
                else if (current.RankedSignatureIndex <
                         signatureIndexList[signatureIndex])
                {
                    if (thresholdReached)
                    {
                        // Threshold reached so we can removed this item
                        // from the list as it's not relevant.
                        var nextItem = current.Next;
                        if (current.Frequency < maxCount)
                        {
                            linkedList.Remove(current);
                        }
                        current = nextItem;
                    }
                    else
                    {
                        current = current.Next;
                    }
                }
                else
                {
                    // They're the same so increase the frequency and move to the next
                    // element in each.
                    current.Frequency++;
                    if (current.Frequency > maxCount)
                    {
                        maxCount = current.Frequency;
                    }
                    signatureIndex++;
                    current = current.Next;
                }
            }
            if (thresholdReached == false)
            {
                // Add any signature indexes higher than the base list to the base list.
                while (signatureIndex < signatureIndexList.Length)
                {
                    linkedList.Add(new PossibleSignature(
                                       signatureIndexList[signatureIndex], 1));
                    signatureIndex++;
                }
            }
            return(maxCount);
        }