예제 #1
0
파일: DualStamp.cs 프로젝트: chargen/AGI-X0
 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));
 }
예제 #2
0
파일: Stamp.cs 프로젝트: chargen/AGI-X0
        // 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;
        }
예제 #3
0
파일: DualStamp.cs 프로젝트: chargen/AGI-X0
 // 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));
     }
 }
예제 #4
0
파일: Stamp.cs 프로젝트: chargen/AGI-X0
        /**
         * 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);
        }
예제 #5
0
파일: DualStamp.cs 프로젝트: chargen/AGI-X0
        // 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);
        }
예제 #6
0
파일: DualStamp.cs 프로젝트: chargen/AGI-X0
        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);
        }
예제 #7
0
파일: DualStamp.cs 프로젝트: chargen/AGI-X0
        // 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);
        }
예제 #8
0
파일: Stamp.cs 프로젝트: chargen/AGI-X0
        /**
         * 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);
        }
예제 #9
0
파일: DualStamp.cs 프로젝트: chargen/AGI-X0
        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));
        }
예제 #10
0
파일: DualStamp.cs 프로젝트: chargen/AGI-X0
 // 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));
 }