/// <summary> /// Build the specified seq, sigma and t. /// </summary> public void Build(IList<int> seq, int sigma, short t = 16, IIEncoder32 rl2_coder = null, short rl2_block_size = 127) { // 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 = BitmapBuilder (bb_lens); this.PERM = new SuccRL2CyclicPerms_MRRR (); if (rl2_coder == null) { rl2_coder = new EliasGamma32 (); } var build_params = new SuccRL2CyclicPerms_MRRR.BuildParams (rl2_coder, rl2_block_size); this.PERM.Build (P, t, build_params); }
public static IList<int> CreateSortedList(FakeBitmap bitmap) { return new SortedListRSCache (bitmap.GetGGMN (12)); }
public void Build(IList<long> orderedList, long n, byte numLowerBits, BitmapFromBitStream H_builder) { //this.M = orderedList.Count; int M = orderedList.Count; this.N = n; if (M > this.N) { Console.WriteLine ("XXXXX LastItem: {0}", orderedList [orderedList.Count - 1]); throw new ArgumentOutOfRangeException (String.Format ("SArray N < M, N: {0}, M: {1}", this.N, M)); } if (numLowerBits < 1) { numLowerBits = 1; } // this.NumLowerBits = numLowerBits; this.L = new ListIFS (numLowerBits, new BitStream32 ((numLowerBits / 32) * M)); // Creating bitmaps // 2^ (log N - log N / M) = 2^ \log N M / N = M. // 2^ (log N - log N / M) = 2^ \log N M / N = M. int numpart = (int)Math.Ceiling (Math.Pow (2, (Math.Ceiling (Math.Log (this.N)) - this.GetNumLowerBits ()))); var H_stream = new BitStream32 (M + (numpart / 32 + 1)); long mask = this.get_mask (); int prevblock = -1; for (int i = 0; i < M; i++) { this.L.Add ((int)(orderedList [i] & mask)); int currentblock = (int)(orderedList [i] >> this.GetNumLowerBits ()); if (prevblock != currentblock) { while (prevblock < currentblock) { H_stream.Write (false); prevblock++; } } H_stream.Write (true); } //an additional technical zero H_stream.Write (false, M - prevblock); H_stream.Write (false); if (H_builder == null) { H_builder = BitmapBuilders.GetDArray_wt(16,32); } var fb = new FakeBitmap(H_stream); this.H = H_builder(fb); }
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); }