// GetLinks takes a UID instead of a PUID because it uses the uid to decomress the
            // UID's first link, and an on-the-fly translation would require the PUID-to-UID
            // translation table to be loaded at all times.
            internal List <long> GetLinks(long uid, long firstTime, long lastTime)
            {
                Contract.Requires(this.linkCell.cell.UidInLinkCell(uid));
                Contract.Ensures(Contract.Result <List <long> >() != null);
                Contract.Ensures(UID.LinksAreSorted(Contract.Result <List <long> >()));

                long puid = this.linkCell.cell.part.ping.PUID(uid);

                if (puid != this.nextPuid)
                {
                    long block = puid / this.linkCell.indexStride;
                    this.decompressor.SetPosition(this.linkCell.idxOffsets[block]);
                    for (long pos = block * this.linkCell.indexStride; pos < puid; pos++)
                    {
                        uint m = this.decompressor.GetUInt32();
                        for (uint j = 0; j < m; j++)
                        {
                            // First gap (i=0) is actually an Int64, but I don't care
                            this.decompressor.GetUInt64();
                        }
                    }
                }
                uint n        = this.decompressor.GetUInt32();
                var  linkUids = new List <long>((int)n);
                var  linkUid  = uid;

                for (uint j = 0; j < n; j++)
                {
                    long gap = j == 0
                  ? this.decompressor.GetInt64()
                  : (long)this.decompressor.GetUInt64();
                    linkUid += gap;
                    linkUids.Add(linkUid);
                }

                uint r                = this.decompressor.GetUInt32();
                var  revision         = new List <long>((int)r);
                long currentTimeStamp = 0;;

                for (uint j = 0; j < r; j++)
                {
                    currentTimeStamp = (j == 0) ? (long)this.decompressor.GetUInt64() : (currentTimeStamp + (long)this.decompressor.GetUInt64());
                    revision.Add(currentTimeStamp);
                }

                var length = TempUtils.getBitMatrixLength((uint)revision.Count, (uint)linkUids.Count);

                UInt32[] bit_matrix = new UInt32[length];
                for (uint j = 0; j < length; j++)
                {
                    bit_matrix[j] = (j == 0) ? this.decompressor.GetUInt32() : (bit_matrix[j - 1] + this.decompressor.GetUInt32());
                }

                var linkInTime = TempUtils.getListOfUidInTimeStamp(revision, bit_matrix, linkUids, firstTime, lastTime);

                // TODO: Insert code to read time data to here

                this.nextPuid = puid + 1;
                return(linkInTime);
            }
Ejemplo n.º 2
0
        public static UInt32[] ConvertTimeSeriesToByteArray(List <List <long> > linkRevsUids, List <long> linkTotalUids)
        {
            uint length = TempUtils.getBitMatrixLength((uint)linkRevsUids.Count, (uint)linkTotalUids.Count);

            UInt32[] bit_matrix = new UInt32[length];

            for (int i = 0; i < linkRevsUids.Count; i++)
            {
                var linkRevUids = linkRevsUids[i];
                for (int j = 0; j < linkTotalUids.Count; j++)
                {
                    long id = linkTotalUids[j];
                    if (linkRevUids.BinarySearch(id) >= 0)
                    {
                        var currentPos = i * linkTotalUids.Count + j;
                        bit_matrix[currentPos / RADIX] += VALUE_AT_BIT[(RADIX - 1) - currentPos % RADIX];
                    }
                }
            }
            return(bit_matrix);
        }