Inheritance: natix.CompactDS.RankSelectBase
Example #1
0
 public void Build(SATSEQ sat)
 {
     this.DB = sat.DB;
     this.SEQ = sat.SEQ;
     this.COV = sat.COV;
     this.root = sat.root;
     this.COV_ZERO = sat.COV_ZERO;
 }
Example #2
0
 public GGMN GetGGMN(short step)
 {
     var g = new GGMN ();
     g.Build (this.B, step);
     return g;
 }
Example #3
0
 public void Save_CSA_BWT(string sa_name, int sample_step)
 {
     Console.WriteLine ("Save_CSA_BWT destroys the SA, if you need the plain SA");
     Console.WriteLine ("first save it and reload it after the call");
     using (var Output = new BinaryWriter (File.Create (sa_name + ".structs"))) {
         RankSelectGenericIO.Save (Output, this.newF);
         PrimitiveIO<int>.WriteVector (Output, this.charT);
     }
     using (var Output = new BinaryWriter (File.Create (sa_name + ".samples"))) {
         Output.Write ((short)sample_step);
         var B = new BitStream32 ();
         int numbits = (int)Math.Ceiling (Math.Log (this.SA.Length, 2));
         var SA_samples = new List<int> ();
         var SA_invsamples = new List<int> ();
         for (int i = 0; i < this.SA.Length; i++) {
             var s = this.SA[i];
             if ((s + 1 == this.SA.Length) || (s % sample_step == 0)) {
                 B.Write (true);
                 SA_samples.Add (s);
                 SA_invsamples.Add (i);
             } else {
                 B.Write (false);
             }
         }
         GGMN G = new GGMN ();
         G.Build (B, 8);
         RankSelectGenericIO.Save (Output, G);
         {
             var _SA_samples = new ListIFS (numbits);
             foreach (var u in SA_samples) {
                 _SA_samples.Add (u);
             }
             _SA_samples.Save (Output);
         }
         {
             Sorting.Sort<int, int> (SA_samples, SA_invsamples);
             var _SA_invsamples = new ListIFS (numbits);
             foreach (var u in SA_invsamples) {
                 _SA_invsamples.Add (u);
             }
             _SA_invsamples.Save (Output);
             SA_samples = null;
             SA_invsamples = null;
         }
     }
     // building bwt
     using (var Output = new BinaryWriter (File.Create (sa_name + ".bwt"))) {
         int alphabet_numbits = (int)Math.Ceiling (Math.Log (this.charT.Count + 1, 2));
         var L = new ListIFS (alphabet_numbits);
         int bwt_len = this.SA.Length;
         for (int i = 0; i < bwt_len; i++) {
             var v = this.SA[i];
             if (v == 0) {
                 L.Add (0);
             } else {
                 // Output.Write ("{0} ", (int)this.Text[v - 1]);
                 var c = this.Text[v - 1];
                 var u = GenericSearch.FindLast<int> (c, this.charT, 1, this.charT.Count);
                 L.Add (u);
             }
         }
         L.Save (Output);
     //				for (int i = 0; i < bwt_len; i++) {
     //					var v = this.SA[i];
     //					if (v == 0) {
     //						Output.Write ("{0} ", -1);
     //					} else {
     //						// Output.Write ("{0} ", (int)this.Text[v - 1]);
     //						var c = this.Text[v - 1];
     //						var u = GenericSearch.FindLast<int> (c, this.charT);
     //						Output.Write ("{0} ", u);
     //					}
     //				}
         // PrimitiveIO<byte>.WriteVector (Output, BWT);
     }
     // building psi
     using (var Output = new BinaryWriter (File.Create (sa_name + ".psi"))) {
         var INV = new int[this.SA.Length];
         for (int i = 0; i < INV.Length; i++) {
             INV[this.SA[i]] = i;
         }
         var PSI = this.SA;
         for (int i = 0; i < PSI.Length; i++) {
             var p = (PSI[i] + 1) % PSI.Length;
             PSI[i] = INV[p];
         }
         PrimitiveIO<int>.WriteVector (Output, PSI);
         /*Console.Write ("charT => ");
         for (int i = 0; i < this.charT.Count; i++) {
             Console.Write ("[{0}] ", (char)this.charT[i]);
         }
         Console.WriteLine ();
         Console.Write ("newF => ");
         for (int i = 0; i < this.newF.Count1; i++) {
             Console.Write ("{0} ", this.newF.Select1(i+1));
         }
         Console.WriteLine ();
         Console.Write ("PSI => ");
         for (int i = 0; i < PSI.Length; i++) {
             Console.Write ("{0} ", PSI[i]);
         }
         Console.WriteLine ();
          */
         INV = null;
     }
     this.SA = null;
 }
Example #4
0
 public void Load(BinaryReader br, bool load_bitmap)
 {
     this.B = br.ReadInt32 ();
     int posabslen = br.ReadInt32 ();
     int expposlen = br.ReadInt32 ();
     this.PosAbs = new int[posabslen];
     this.SavedPos = new int[expposlen];
     PrimitiveIO<int>.ReadFromFile (br, posabslen, this.PosAbs);
     PrimitiveIO<int>.ReadFromFile (br, expposlen, this.SavedPos);
     this.IsLargeBlock = new GGMN ();
     this.IsLargeBlock.Load (br);
     this.BaseIndex = new GGMN ();
     this.BaseIndex.Load (br, load_bitmap);
 }
Example #5
0
 public void BuildBackend(IList<uint> bitblocks, short Brank, int Bselect, int N)
 {
     this.BaseIndex = new GGMN ();
     this.BaseIndex.BuildBackend (bitblocks, N, Brank);
     this.B = Bselect;
     int M = this.BaseIndex.Rank1 (N - 1);
     // Console.WriteLine("XXXX N: {0}, M: {1}", N, M);
     this.PosAbs = new int[(int)Math.Ceiling (M * 1.0 / this.B)];
     int m = 0;
     int i = 0;
     int large_limit = 32 * this.B;
     BitStream32 mark_bits = new BitStream32 (this.PosAbs.Count >> 5);
     int num_saved_slots = 0;
     while (m < M) {
         int start_pos = this.BaseIndex.Select1 (m + 1);
         int Bmin = Math.Min (this.B, M - m);
         int end_pos = this.BaseIndex.Select1 (m + Bmin);
         if (end_pos - start_pos >= large_limit) {
             mark_bits.Write (true);
             num_saved_slots += Bmin;
         } else {
             mark_bits.Write (false);
             // uncomment to make all large blocks (debugging). Comment the previous line to enable to following
             // mark_bits.Write (true);
             // num_saved_slots += Bmin;
         }
         this.PosAbs[i] = start_pos;
         m += this.B;
         i++;
     }
     this.IsLargeBlock = new GGMN ();
     this.IsLargeBlock.Build (mark_bits, 4);
     int R = this.IsLargeBlock.Rank1 (this.IsLargeBlock.Count - 1);
     this.SavedPos = new int[num_saved_slots];
     for (int k = 0; k < R; k++) {
         int index = this.IsLargeBlock.Select1 (k + 1);
         int rank_base = this.B * index;
         int index_base = this.B * k;
         int maxB = Math.Min (this.B, M - rank_base);
         for (int rank_rel = 0; rank_rel < maxB; rank_rel++) {
             var pos = this.BaseIndex.Select1( rank_rel + rank_base + 1);
             this.SavedPos[rank_rel + index_base] = pos;
         }
     }
 }
Example #6
0
 public void Build(SAT sat)
 {
     var n = sat.DB.Count;
     this.DB = sat.DB;
     var cov = new double[n];
     var seq = new int[n];
     this.root = sat.root.objID;
     int nonzeros = 0;
     var visit = new Action<SAT.Node,SAT.Node>((parent, child) => {
         seq[child.objID] = (parent == null) ? n : parent.objID;
         cov[child.objID] = child.cov;
         if (child.cov > 0) ++nonzeros;
     });
     visit (null, sat.root);
     this.Build_IterateSAT (sat.root, visit);
     var listibuilder = ListIBuilders.GetArray ();
     var permbuilder = PermutationBuilders.GetCyclicPerms (1, listibuilder, listibuilder);
     var seqbuilder = SequenceBuilders.GetSeqSinglePerm (permbuilder);
     this.SEQ = seqbuilder (seq, n + 1);
     this.COV = new List<double> (nonzeros);
     var cov_zero = new BitStream32 ();
     cov_zero.Write (true, n);
     for (int objID = 0; objID < n; ++objID) {
         if (cov[objID] > 0) {
             this.COV.Add(cov[objID]);
             cov_zero[objID] = false;
         }
     }
     this.COV_ZERO = new GGMN ();
     this.COV_ZERO.Build (cov_zero, 8);
 }
Example #7
0
 public override void Load(BinaryReader Input)
 {
     base.Load (Input);
     this.root = Input.ReadInt32 ();
     this.SEQ = GenericIO<Sequence>.Load (Input);
     var len = Input.ReadInt32 ();
     this.COV = new List<double> (len);
     PrimitiveIO<double>.LoadVector (Input, len, this.COV);
     this.COV_ZERO = new GGMN ();
     this.COV_ZERO.Load (Input);
 }
Example #8
0
 public static BitmapFromList GetGGMN(short sample_step)
 {
     return delegate (IList<int> L) {
         var rs = new GGMN ();
         rs.Build (L, sample_step);
         return rs;
     };
 }
Example #9
0
 public void Sort()
 {
     this._numerical_sort (0, 0, this.SA.Length - 1);
     // this._sort(0, 0, this.SA.Length-1);
     // creating auxiliar structures and bitmaps
     this.charT = new List<int> ();
     var B_newF = new BitStream32 ();
     this.charT.Add ('$'); // the special lexicographically smaller symbol
     B_newF.Write (true);
     for (int i = 1; i < this.SA.Length; i++) {
         var c = this.TXT[this.SA[i]];
         if (i == 1) {
             this.charT.Add (c);
             B_newF.Write (true);
         } else {
             if (this.charT[this.charT.Count - 1] != c) {
                 this.charT.Add (c);
                 B_newF.Write (true);
             } else {
                 B_newF.Write (false);
             }
         }
     }
     this.newF = new GGMN ();
     this.newF.Build (B_newF, 8);
 }