Beispiel #1
0
        public void Build(IList<int> seq, int sigma, PermutationBuilder perm_builder, BitmapFromBitStream bitmap_builder)
        {
            // NOTE: Please check sigma <=> BlockSize in this method
            this.sigma = sigma;
            this.n = seq.Count;
            var B_stream = new BitStream32 ();
            var X_stream = new BitStream32[ sigma ];
            for (int i = 0; i < sigma; i++) {
                X_stream [i] = new BitStream32 ();
            }
            var lists = new List<int>[sigma];
            for (int i = 0; i < sigma; i++) {
                lists [i] = new List<int> ();
            }
            int num_blocks = (int)Math.Ceiling (this.n * 1.0 / this.sigma);
            this.perms = new List<IPermutation> (num_blocks);
            for (int i = 0; i < this.n; i+= this.sigma) {
                // writing block separators
                foreach (var b in X_stream) {
                    b.Write (true);
                }
                // clearing perm B
                // selecting block size
                int s = Math.Min (this.n - i, this.sigma);
                this.BuildPermInvIndex (seq, i, s, lists);
                var P = new List<int> (s);
                for (int j = 0; j < this.sigma; j++) {
                    var c = lists [j].Count;
                    B_stream.Write (false);
                    if (c > 0) {
                        X_stream [j].Write (false, c);
                        B_stream.Write (true, c);
                        foreach (var u in lists[j]) {
                            P.Add (u);
                        }
                    }
                }
                var _perm = perm_builder(P);
                this.perms.Add (_perm);
            }
            var _X_stream = X_stream [0];

            for (int i = 1; i < X_stream.Length; i++) {
                var _X_curr = X_stream [i];
                for (int j = 0; j < _X_curr.CountBits; j++) {
                    // esto se podria hace por entero en lugar de bit
                    _X_stream.Write (_X_curr [j]);
                }
            }
            // If we write a zero at the end of the streams the code is simplified
            _X_stream.Write (true);
            B_stream.Write (false);
            this.B = bitmap_builder (new FakeBitmap (B_stream));
            this.X = bitmap_builder (new FakeBitmap (_X_stream));
            this.compute_num_blocks ();
        }
Beispiel #2
0
        public void Build(IList<int> seq, int sigma, PermutationBuilder perm_builder, BitmapFromBitStream bitmap_builder)
        {
            // A counting sort construction of the permutation
            var counters = new int[sigma];
            foreach (var s in seq) {
                if (s + 1 < sigma) {
                    counters [s + 1]++;
                }
            }
            for (int i = 1; i < sigma; i++) {
                counters [i] += counters [i - 1];
            }
            var n = seq.Count;
            var P = new int[n];
            for (int i = 0; i < n; i++) {
                var sym = seq [i];
                var pos = counters [sym];
                P [pos] = i;
                counters [sym] = pos + 1;
            }
            // the bitmap to save the lengths
            var lens = new BitStream32 ();
            int prevc = 0;
            foreach (var c in counters) {
                var len = c - prevc;
                prevc = c;
                lens.Write (true);
                lens.Write (false, len);
            }
            // an additional 1 to the end, to simplify source code
            lens.Write (true);

            var bb_lens = new FakeBitmap (lens);
            this.LENS = bitmap_builder(bb_lens);
            this.PERM = perm_builder(P);
        }
Beispiel #3
0
 public static SequenceBuilder GetSeqSinglePerm(PermutationBuilder perm_builder = null, BitmapFromBitStream bitmap_builder = null)
 {
     if (perm_builder == null) {
         perm_builder = PermutationBuilders.GetCyclicPermsListIDiffs (16, 63);
     }
     if (bitmap_builder == null) {
         bitmap_builder = BitmapBuilders.GetGGMN_wt(8);
     }
     return delegate (IList<int> seq, int sigma) {
         var S = new SeqSinglePerm ();
         S.Build (seq, sigma,perm_builder, bitmap_builder);
         return S;
     };
 }
Beispiel #4
0
 public static SequenceBuilder GetGolynskiSinglePerm(PermutationBuilder pbuilder)
 {
     return delegate (IList<int> seq, int sigma) {
         var S = new GolynskiSinglePermSeq ();
         S.PermBuilder = pbuilder;
         S.Build (seq, sigma);
         return S;
     };
 }