Exemplo n.º 1
0
        /// <summary>
        /// Builds the index for the sequence
        /// </summary>
        public void Build(IList<int> sequence, int alphabet_size, int t = 16,
		                   BitmapFromList rowbuilder = null, BitmapFromBitStream lenbuilder = null)
        {
            if (rowbuilder == null) {
                rowbuilder = BitmapBuilders.GetSArray ();
            }
            if (lenbuilder == null) {
                lenbuilder = BitmapBuilders.GetGGMN_wt (12);
            }
            var invindex = new IList<int>[alphabet_size];
            for (int i = 0; i < alphabet_size; i++) {
                invindex [i] = new List<int> ();
            }
            int pos = 0;
            foreach (var c in sequence) {
                invindex [c].Add (pos);
                pos++;
            }
            pos = 0;
            this.N = sequence.Count;
            this.InvIndex = new Bitmap[alphabet_size];
            var lens = new BitStream32 ();
            for (int i = 0; i < alphabet_size; i++) {
                if (i % 1000 == 0) {
                    if (i % 10000 == 0) {
                        Console.WriteLine ();
                        Console.Write ("*** InvIndexXLBSeq {0}/{1}", i, alphabet_size);
                    } else {
                        Console.Write (", {0}", i);
                    }
                }
                this.InvIndex [i] = rowbuilder (invindex [i]);
                lens.Write (true);
                lens.Write (false, invindex [i].Count);
                invindex [i] = null;
            }
            lens.Write (true);
            Console.WriteLine ();
            Console.WriteLine ("done, now saving permutation and the Len bitmap");
            this.Lens = lenbuilder (new FakeBitmap (lens));
            var p = new ListGen_MRRR ();
            p.Build (this.GetNotIdxPERM (), t, null);
            Console.WriteLine ("done");
            this.Perm = p;
        }
Exemplo n.º 2
0
        public void Build(IList<int> seq, int sigma, int t = 16, BitmapFromList64 bitmap_builder = null)
        {
            this.sigma = sigma;
            long n = seq.Count;
            var L = new long[n];

            var counters = new int[sigma + 1];
            // counters.Add (0, sigma); <- if ListIFS
            for (int i = 0; i < n; ++i) {
                var sym = seq [i];
                try {
                    counters [sym + 1] += 1;
                } catch (Exception e) {
                    Console.WriteLine ("===== sigma: {0}, sym: {1}, i: {2}, n: {3}", sigma, sym, i, n);
                    throw e;
                }
            }
            for (int i = 1; i <= sigma; ++i) {
                counters [i] += counters [i - 1];
            }
            for (int i = 0; i < n; ++i) {
                var sym = seq [i];
                long long_sym = n * ((long)sym) + i;
                L [counters [sym]] = long_sym;
                counters [sym] += 1;
            }
            counters = null;
            /**** slow construction ****/
            /*****
            for (int i = 0; i < n; ++i) {
                long s = seq [i];
                L [i] = n * s + i;
                //L.Add (n * s + i);
            }
            Array.Sort (L);
            *****/
            if (bitmap_builder == null) {
                bitmap_builder = BitmapBuilders.GetSArray64 ();
            }
            this.xl_bitmap = bitmap_builder (L, n * sigma);
            // now building the permutation for access
            var p = new ListGen_MRRR ();
            p.Build (this.GetNotIdxPERM (), t, null);
            this.perm = p;
        }