Exemplo n.º 1
0
 public bool collide(DualStamp a, DualStamp b)
 {
     return
         (collideByBloomfilter(a, b) && // fast rejection by checking if the bits overlap, if at least one bit does overlap it could overlap
          collideIterateHistoryAndCheckBloomfilter(a, b) &&
          collideIterateHistorySlow(a, b));
 }
Exemplo n.º 2
0
        // force construction with make static methods
        /** used for when the ocrrence time will be set later; so should not be called from externally but through another Stamp constructor */
        private Stamp(EnumTense tense, long serial)
        {
            dualStamp = new DualStamp(Parameters.STAMP_NUMBEROFELEMENTS, Parameters.STAMP_BLOOMFILTERNUMBEROFBITS);
            dualStamp.insertAtFront(new List <uint> {
                // HACK< stamps must store long !!! >
                (uint)serial
            });

            this.tense = tense;
        }
Exemplo n.º 3
0
 // iterates over the termIdHistory of the stamp with the least number of entries and checks in the bloomfilter of the other if the bit is set
 protected bool collideIterateHistoryAndCheckBloomfilter(DualStamp a, DualStamp b)
 {
     if (a.privateUsed < b.privateUsed)
     {
         return(collideIterateHistoryAndCheckBloomfilterHelper(a, b));
     }
     else
     {
         return(collideIterateHistoryAndCheckBloomfilterHelper(b, a));
     }
 }
Exemplo n.º 4
0
        /**
         * Generate a new stamp for derived sentence by merging the two from parents
         * the first one is no shorter than the second
         *
         * \param first The first Stamp
         * \param second The second Stamp
         */
        public static Stamp zipWithTime(
            Stamp first,
            Stamp second,
            long time
            )
        {
            Debug.Assert(first.dualStamp.used >= second.dualStamp.used);

            Stamp result = new Stamp();

            result.dualStamp      = DualStamp.zip(first.dualStamp, second.dualStamp);
            result.creationTime   = time;
            result.occurrenceTime = first.occurrenceTime;
            return(result);
        }
Exemplo n.º 5
0
        // iterates over the termIdHistory of a and checks if the coresponding entry in b in the bloomfilter is set
        protected bool collideIterateHistoryAndCheckBloomfilterHelper(DualStamp a, DualStamp b)
        {
            Debug.Assert(a.privateUsed <= numberOfElements);

            for (int i = 0; i < a.privateUsed; i++)
            {
                /*TermId*/ uint aTermId  = a.termIdHistory[i];
                bool            isSetInB = b.bloomfilter.test(aTermId);
                if (isSetInB)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        public static DualStamp zip(DualStamp a, DualStamp b)
        {
            DualStamp result = new DualStamp(a.numberOfElements, a.bloomfilter.numberOfBits);

            uint newUsed = Math.Min((uint)(a.privateUsed + b.privateUsed), (uint)a.numberOfElements);

            int ai = 0, bi = 0;

            IList <uint> zipped = new List <uint>();

            // zip
            for (;; ai++, bi++)
            {
                if (ai == a.used || bi == b.used)
                {
                    break;
                }

                zipped.Add(a.accessTermIdHistory(ai));
                zipped.Add(b.accessTermIdHistory(bi));
            }

            // remainder
            for (;; ai++)
            {
                if (ai == a.used)
                {
                    break;
                }

                zipped.Add(a.accessTermIdHistory(ai));
            }

            for (; ; bi++)
            {
                if (bi == b.used)
                {
                    break;
                }

                zipped.Add(b.accessTermIdHistory(bi));
            }

            result.insertAtFront(zipped);
            result.recalcBloomfilter(newUsed);
            return(result);
        }
Exemplo n.º 7
0
        // ASK PATRICK< is this algorithm right to check all n to n or should we just check for common sequences? >
        protected bool collideIterateHistorySlow(DualStamp a, DualStamp b)
        {
            Debug.Assert(a.privateUsed <= numberOfElements);
            Debug.Assert(b.privateUsed <= numberOfElements);

            for (int ia = 0; ia < a.privateUsed; ia++)
            {
                for (int ib = 0; ib < b.privateUsed; ib++)
                {
                    /*TermId*/ uint aTermId = a.termIdHistory[ia];
                    /*TermId*/ uint bTermId = b.termIdHistory[ib];
                    if (aTermId == bTermId)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 8
0
        /**
         * Check if two stamps contains the same types of content
         *
         * \param a The Stamp to be compared
         * \param b The Stamp to be compared
         * \return Whether the two have contain the same evidential base
         */
        public static bool checkEquals(
            Stamp a,
            Stamp b,
            EnumCompareCreationTime compareCreatingTime,
            EnumCompareOccurrenceTime compareOccurrenceTime,
            EnumCompareEvidentialBaseTime compareEvidentialBase
            )
        {
            if (a == b)
            {
                return(true);
            }

            if (compareCreatingTime == EnumCompareCreationTime.YES)
            {
                if (a.creationTime != b.creationTime)
                {
                    return(false);
                }
            }

            if (compareOccurrenceTime == EnumCompareOccurrenceTime.YES)
            {
                if (a.occurrenceTime != b.occurrenceTime)
                {
                    return(false);
                }
            }

            if (compareEvidentialBase == EnumCompareEvidentialBaseTime.YES)
            {
                // TODO if (a.evidentialHash != b.evidentialHash) return false;

                if (!DualStamp.checkEqual(a.dualStamp, b.dualStamp))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 9
0
        public static bool checkEqual(DualStamp a, DualStamp b)
        {
            if (a.privateUsed != b.privateUsed)
            {
                return(false);
            }

            ISet <uint> aSet = new HashSet <uint>();

            for (int i = 0; i < a.privateUsed; i++)
            {
                aSet.Add(a.termIdHistory[i]);
            }

            ISet <uint> bSet = new HashSet <uint>();

            for (int i = 0; i < b.privateUsed; i++)
            {
                bSet.Add(b.termIdHistory[i]);
            }

            return(aSet.Overlaps(bSet) && bSet.Overlaps(aSet));
        }
Exemplo n.º 10
0
 // returns if the two bloomfilter (can) collide by checking if bits of the bloomfilters overlap
 protected static bool collideByBloomfilter(DualStamp a, DualStamp b)
 {
     return(BloomfilterType.overlap(a.bloomfilter, b.bloomfilter));
 }