static void Main(string[] args) { List <List <string> > words_4000 = JsonConvert.DeserializeObject <List <List <string> > >(File.ReadAllText(@"D:\Git\WordBlocksGDX\Android Project 1 - Word Blocks\4000 words.json")); List <List <List <string> > > usedWords = JsonConvert.DeserializeObject <List <List <List <string> > > >(File.ReadAllText(@"D:\WORD\usedWords7.json")); //words_4000 = removeUsedWords(usedWords, words_4000); ListGen listGen = new ListGen(words_4000); List <List <List <string> > > allLevels = new List <List <List <string> > >(); allLevels.Add(listGen.Generate(7, 250)); //allLevels.Add(listGen.Generate(4, 100)); //allLevels.Add(listGen.Generate(5, 15)); //allLevels.Add(listGen.Generate(6, 160)); //allLevels.Add(listGen.Generate(7, 180)); string allText = JsonConvert.SerializeObject(allLevels); //File.WriteAllText("D:/allLevelsSoFar3-5.json", allText); //allText = JsonConvert.SerializeObject(allLevels); //File.WriteAllText("D:/allLevelsSoFar6.json", allText); System.Console.WriteLine("TOTAL WORDS USED: " + listGen.freq.Count); //allText = JsonConvert.SerializeObject(allLevels); File.WriteAllText("D:/allLevelsSoFar.json", allText); Console.ReadLine(); }
public ActionResult Edit(int listId) { ListGen listgen = db.ListGens.Include(l => l.Tasks).Single(l => l.ListGenId == listId); ViewBag.GenreId = new SelectList(db.ListGens, "ListGenId", "Name", listgen.ListGenId); return(View(listgen)); }
private void FromSBRecursion(Primitive sbArray, ListGen listTo, bool bValues) { Dictionary <Primitive, Primitive> _arrayMap = (Dictionary <Primitive, Primitive>)_fieldInfo.GetValue(Utilities.CreateArrayMap(sbArray)); if (_arrayMap.Count > 0) { foreach (KeyValuePair <Primitive, Primitive> kvp in _arrayMap) { Dictionary <Primitive, Primitive> _arrayMap1 = (Dictionary <Primitive, Primitive>)_fieldInfo.GetValue(Utilities.CreateArrayMap(kvp.Value)); listGen = new ListGen(); listTo.Add(listGen); if (_arrayMap1.Count > 0) { FromSBRecursion(kvp.Value, listGen, bValues); } else { listGen.Value = bValues ? kvp.Value : kvp.Key; } } } else { if (bValues) { listTo.Value = sbArray; } } }
public void WriteCSV(string fileName) { try { string[] output = new string[listGenMain.Count]; for (int iRow = 0; iRow < listGenMain.Count; iRow++) { listGen = listGenMain[iRow]; for (int iCol = 0; iCol < listGen.Count; iCol++) { output[iRow] += Utilities.CSVParse(listGen[iCol].Value, true) + Utilities.CSV; } if (output[iRow].Length > 0) { output[iRow] = output[iRow].Substring(0, output[iRow].Length - 1); } } System.IO.File.WriteAllLines(fileName, output); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }
public int Dimension() { listGen = listGenMain; int maxDimension = 0; DimensionRecursion(listGenMain, 0, ref maxDimension); return(maxDimension); }
public ActionResult Delete(int id, FormCollection collection) { ListGen listgen = db.ListGens.Find(id); db.ListGens.Remove(listgen); db.SaveChanges(); return(RedirectToAction("Index")); }
private void CopyRecursion(ListGen listFrom, ListGen listTo) { for (int i = 0; i < listFrom.Count; i++) { listTo.Add(new ListGen()); listTo[i].Value = listFrom[i].Value; CopyRecursion(listFrom[i], listTo[i]); } }
public ActionResult Create(ListGen listgen) { if (ModelState.IsValid) { db.ListGens.Add(listgen); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ListGenId = new SelectList(db.ListGens, "ListGenId", "Name"); return(View(listgen)); }
/// <summary> /// Retrieves the Nth element. /// </summary> private FormattedParts GetEntry(int index) { FormattedParts parts = mList[index]; if (parts == null) { parts = mList[index] = ListGen.GetFormattedParts(index); parts.ListIndex = index; } return(parts); }
public ActionResult Edit(ListGen listgen) { if (ModelState.IsValid) { db.Entry(listgen).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.GenreId = new SelectList(db.ListGens, "ListGenId", "Name", listgen.ListGenId); return(View(listgen)); }
private void DimensionRecursion(ListGen list, int parentDimension, ref int maxDimension) { if (list.Count > 0) { maxDimension = System.Math.Max(maxDimension, parentDimension + 1); for (int i = 0; i < list.Count; i++) { DimensionRecursion(list[i], parentDimension + 1, ref maxDimension); } } }
public void SearchTThreshold(IList<IList<int>> PostingLists, int T, out IList<int> docs, out IList<short> card) { if (PostingLists.Count == 0) { docs = new List<int> (); } else if (PostingLists.Count == 1) { docs = PostingLists[0]; } else { docs = new List<int> (this.intersection.Intersection (PostingLists)); } this.CompCounter = this.intersection.CompCounter; card = new ListGen<short> ((int i) => (short)PostingLists.Count, docs.Count); }
private void WriteRecursion(ListGen listFrom, BinaryWriter bw) { bw.Write(listFrom.Count); if (listFrom.Count == 0) { bw.Write((string)listFrom.Value); } for (int i = 0; i < listFrom.Count; i++) { WriteRecursion(listFrom[i], bw); } }
private void CollapseRecursion(ListGen listFrom) { for (int i = listFrom.Count - 1; i >= 0; i--) { if (listFrom[i].Count == 0 && listFrom[i].Value == "") { listFrom.RemoveAt(i); continue; } CollapseRecursion(listFrom[i]); } }
public void FromSB(Primitive sbArray, bool bValues) { try { listGenMain = new ListGen(); FromSBRecursion(sbArray, listGenMain, bValues); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }
private void ReadRecursion(ListGen listTo, BinaryReader br) { int num = br.ReadInt32(); if (num == 0) { listTo.Value = br.ReadString(); } for (int i = 0; i < num; i++) { listTo.Add(new ListGen()); ReadRecursion(listTo[i], br); } }
public ActionResult DeleteAll(int id, FormCollection collection) { ListGen listgen = db.ListGens.Find(id); // db.ListGens.Remove(listgen); List <Task> tasksdelet = new List <Task>(); tasksdelet.AddRange(listgen.Tasks); foreach (var listgentask in tasksdelet) { db.Tasks.Remove(listgentask); } db.ListGens.Remove(listgen); db.SaveChanges(); return(RedirectToAction("Index")); }
public int Size() { try { listGen = listGenMain; for (int i = 0; i < numIndex; i++) { listGen = listGen[index[i] - 1]; } return(listGen.Count); } catch { return(0); } }
private void WriteRecursion(ListGen listFrom, StreamWriter sw, string line) { for (int i = 0; i < listFrom.Count; i++) { string newline = line + (i + 1).ToString() + " "; if (listFrom[i].Count == 0) { newline += ": " + listFrom[i].Value; sw.WriteLine(newline); } else { WriteRecursion(listFrom[i], sw, newline); } } }
private Primitive ToSBRecursion(ListGen listFrom, Primitive result) { if (listFrom.Count == 0) { result = listFrom.Value; } else { for (int i = 0; i < listFrom.Count; i++) { Primitive newResult = ""; result[i + 1] = ToSBRecursion(listFrom[i], newResult); } } return(result); }
public Primitive Get() { try { listGen = listGenMain; for (int i = 0; i < numIndex; i++) { listGen = listGen[index[i] - 1]; } return(listGen.Value); } catch { return(""); } }
void HwangLinTwoLists(IList<int> S, int startS, int endS, IList<int> L, int startL, int endL, IList<int> Out) { int m = endS - startS; int n = endL - startL; int blockSize = (int) Math.Ceiling(n * 1.0 / m); int currStartL = startL; // M >>= 2; ListGen<int> Lsample = new ListGen<int> ((int iS) => L[iS * blockSize + currStartL], m); for (int advanceS = startS; advanceS < endS && currStartL < endL;) { Console.WriteLine("M: {0}, N: {1}, L: {2}", m, n, Lsample.Length); int data = S[advanceS]; int occPos; if (this.SampleSearch.Search (data, Lsample, out occPos, 0, Lsample.Length)) { // occPos++; Out.Add (data); currStartL += occPos * blockSize + 1; advanceS++; } else { // if occPos == 0: out of range if (occPos > 0) { occPos--; currStartL += occPos * blockSize; int currEndL = Math.Min (currStartL + blockSize, endL); int currentTopBlockL = L[currEndL-1]; int currEndS; if (this.SampleSearch.Search(currentTopBlockL, S, out currEndS, advanceS, endS)) { // se puede optimizar poniendo casos especiales para cuando // se encuentra y cuando no currEndS++; } this.InOrderI(S, advanceS, currEndS, L, currStartL, currEndL, Out); currStartL = currEndL; advanceS = currEndS; } else { advanceS++; } } m = endS - advanceS; // M >>= 2; n = endL - currStartL; blockSize = (int)Math.Ceiling (n * 1.0 / m); Lsample.Length = m; } }
public void Set(Primitive value) { try { listGen = listGenMain; for (int i = 0; i < numIndex; i++) { int ind = index[i]; for (int j = listGen.Count; j < ind; j++) { listGen.Add(new ListGen()); } listGen = listGen[ind - 1]; } listGen.Value = value; } catch { } }
public void ReadCSV(string fileName) { try { string[] input = System.IO.File.ReadAllLines(fileName); string[] row; List <string[]> rowOrdered = new List <string[]>(); int numRow = input.Length; int numCol = 1; foreach (string line in input) { row = line.Split(new string[] { Utilities.CSV }, StringSplitOptions.None); numCol = System.Math.Max(numCol, row.Length); rowOrdered.Add(row); } listGenMain.Clear(); ListGen listGen1, listGen2; for (int iRow = 0; iRow < numRow; iRow++) { listGen1 = new ListGen(); listGenMain.Add(listGen1); row = rowOrdered[iRow]; for (int iCol = 0; iCol < row.Length; iCol++) { listGen2 = new ListGen(); listGen1.Add(listGen2); listGen2.Value = Utilities.CSVParse(row[iCol], false); } } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }
public override int Select0(int rank) { if (this.AbsComp == null) { int scale = this.B << 5; this.AbsComp = new ListGen<uint> ((int i) => ((uint)((i+1) * scale)) - this.Abs[i], this.Abs.Count); this.BitBlocksComp = new ListGen<uint> ((int u) => ~this.BitBlocks[u], this.BitBlocks.Count); } if (rank <= 0) { return -1; } int absindex = GenericSearch.FindFirst<uint> ((uint)rank, AbsComp); if (absindex >= 0 && AbsComp[absindex] == rank) { absindex--; } if (absindex < 0) { return BitAccess.Select1 (BitBlocksComp, 0, this.B, rank); } else { int startindex = (absindex + 1) * this.B; return ((startindex) << 5) + BitAccess.Select1 (BitBlocksComp, startindex, this.B, rank - (int)AbsComp[absindex]); } }
IList<int> _get_suffix_lazy(int suffix) { var E = this.GetSuffixLazy (suffix, this.N).GetEnumerator (); E.MoveNext (); // E.Reset (); var L = new ListGen<int> ((int x) => { var u = E.Current; E.MoveNext (); return u; }, this.N); L.FinalizeInstance = () => { E.Dispose (); return 0; }; return L; }
public bool Search(IList<int> query, out int start_pos, out int end_pos) { // backward search end_pos = start_pos = -1; int m = query.Count - 1; var c = this.GetCharId (query [m]); if (c < 0) { return false; } int sp = this.newF.Select1 (c + 1); int ep = sp + this.newF.Select1(c+2) - this.newF.Select1(c+1); for (--m; m >= 0; --m) { c = this.GetCharId (query [m]); if (c < 0) { return false; } int c_sp = this.newF.Select1(c + 1); int c_ep = this.newF.Select1(c + 2); var L = new ListGen<int>((int i) => this.Psi[i+c_sp], c_ep - c_sp); int abs_pos = c_sp - 1; sp = abs_pos + GenericSearch.FindFirst<int>(sp, L); ep = abs_pos + GenericSearch.FindLast<int>(ep, L); } start_pos = sp; end_pos = ep; return true; }
void HwangLinTwoLists(IList<int> S, int startS, int endS, IList<int> L, int startL, int endL, IList<int> Out) { int m = endS - startS; int n = endL - startL; int blockSize = (int) Math.Ceiling(n * 1.0 / m); int currStartL = startL; // M >>= 2; ListGen<int> Lsample = new ListGen<int> ((int iS) => L[iS * blockSize + currStartL], m); for (int i = startS; i < endS && currStartL < endL; i++) { // Console.WriteLine("M: {0}, N: {1}, L: {2}", M, N, Lsample.Length); int data = S[i]; int occPos; if (this.SampleSearch.Search (data, Lsample, out occPos, 0, Lsample.Length)) { // occPos++; Out.Add (data); currStartL += occPos * blockSize + 1; } else { // if occPos == 0: out of range if (occPos > 0) { occPos--; currStartL += occPos * blockSize; // int currEndL = Math.Min (currStartL + blockSize, endL); if (this.BlockSearch.Search (data, L, out currStartL, currStartL, endL)) { Out.Add (data); currStartL++; } } } m = endS - i; // M >>= 2; n = endL - currStartL; blockSize = (int)Math.Ceiling (n * 1.0 / m); Lsample.Length = m; Console.WriteLine("i: {0}, currStartL: {0}", i, currStartL); Console.WriteLine ("S.Length: {0}, L.Length: {1}", S.Count, L.Count); Console.WriteLine ("End> M: {0}, N: {1}, L: {2}", m, n, Lsample.Length); } }
public ActionResult DeleteAll(int id) { ListGen listgen = db.ListGens.Find(id); return(View(listgen)); }
public ListXD() { NewName(); listGenMain = new ListGen(); }
public void Build(MetricDB db, KnrFP knrfp, int maxcand=1024, SequenceBuilder seq_builder=null) { this.DB = db; this.R = knrfp.IdxRefs; this.K = knrfp.K; this.MAXCAND = maxcand; var M = knrfp.Fingerprints.seqs; // var L = new int[this.K * this.DB.Count]; // int pos = 0; // for (int objID = 0; objID< this.DB.Count; ++objID) { // var u = M [objID]; // for (int i = 0; i < this.K; ++i, ++pos) { // L [pos] = u [i]; // } // } var L = new ListGen<int> ((int i) => M [i / K] [i % K], this.DB.Count * this.K); if (seq_builder == null) { seq_builder = SequenceBuilders.GetSeqXLB_SArray64 (16); } Console.WriteLine ("xxxxx Build L: {0}, R: {1}, db-count: {2}, db: {3}, K: {4}", L.Count, this.R.DB.Count, db.Count, db, K); this.SEQ = seq_builder (L, this.R.DB.Count); }
public virtual int Select1(int rank) { if (rank <= 0) { return -1; } var G = new ListGen<int> ((int i) => this.Rank1 (i), this.Count); return GenericSearch.FindFirst<int> (rank, G); }
public IList<int> GetNotIdxPERM() { long n = this.Count; var gen = new ListGen<int> (delegate(int i) { return (int)(this.xl_bitmap.Select1 (i + 1) % n); }, (int)n); return gen; }
public void Read(string fileName, bool binary) { try { if (binary) { using (FileStream fs = System.IO.File.Open(fileName, FileMode.Open)) { using (BinaryReader br = new BinaryReader(fs, Encoding.UTF8)) { listGenMain.Clear(); ReadRecursion(listGenMain, br); } } } else { using (FileStream fs = System.IO.File.Open(fileName, FileMode.Open)) { using (StreamReader sr = new StreamReader(fs, Encoding.UTF8)) { listGenMain.Clear(); while (sr.Peek() >= 0) { string line = sr.ReadLine(); string[] split = line.Split(' '); if (split.Length == 0) { continue; } List <int> indices = new List <int>(); int index; string value = ""; for (int i = 0; i < split.Length; i++) { if (split[i] == ":" && indices.Count > 0) { for (int j = i + 1; j < split.Length; j++) { value += split[j]; } break; } else if (int.TryParse(split[i], out index)) { indices.Add(index); } else { value = line; indices.Clear(); indices.Add(listGenMain.Count + 1); break; } } listGen = listGenMain; for (int i = 0; i < indices.Count; i++) { index = indices[i]; for (int j = listGen.Count; j < index; j++) { listGen.Add(new ListGen()); } listGen = listGen[index - 1]; } listGen.Value = value; } } } } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } }
void HwangLinTwoLists(IList<int> S, int startS, int endS, IList<int> L, int startL, int endL, IList<int> Out) { int M = endS - startS; int N = endL - startL; int currStartL = startL; // M >>= 2; ListGen<int> Lsample = new ListGen<int> ((int iS) => L[iS * M + currStartL], (int)Math.Ceiling (N * 1.0 / M)); for (int i = startS; i < endS && currStartL < endL; i++) { // Console.WriteLine("M: {0}, N: {1}, L: {2}", M, N, Lsample.Length); int data = S[i]; int occPos; if (this.SampleSearch.Search (data, Lsample, out occPos, 0, Lsample.Length)) { // occPos++; Out.Add (data); currStartL += occPos * M + 1; } else { // if occPos == 0: out of range if (occPos > 0) { occPos--; currStartL += occPos * M; int currEndL = Math.Min (currStartL + M, endL); if (this.BlockSearch.Search (data, L, out currStartL, currStartL, currEndL)) { Out.Add (data); // occPos++; currStartL++; } // currStartL = occPos; } } M = endS - i; // M >>= 2; N = endL - currStartL; Lsample.Length = (int)Math.Ceiling(N * 1.0 / M); } }
public KnrSeqSearch GetSortedByPrefix(SequenceBuilder seq_builder = null, ListIBuilder list_builder = null) { int n = this.DB.Count; var seqs = new int[n][]; var perm = new int[n]; for (int i = 0; i < n; ++i) { seqs [i] = this.GetStoredKnr (i); perm [i] = i; } // please speed up this method using another sorting method // Sorting.Sort<int> (perm, (x,y) => StringSpace<int>.LexicographicCompare (seqs [x], seqs [y])); Sorting.Sort<int[],int> (seqs, perm, (x,y) => StringSpace<int>.LexicographicCompare (x, y)); var S = new ListGen<int> ((int i) => seqs [i / this.K] [i % this.K], n * this.K); if (list_builder == null) { list_builder = ListIBuilders.GetListIFS(); } if (seq_builder == null) { seq_builder = SequenceBuilders.GetSeqXLB_DiffSet64(24, 63); } var knr = new KnrSeqSearch(); knr.DB = new SampleSpace("", this.DB, list_builder(perm, n-1)); knr.K = this.K; knr.MAXCAND = this.MAXCAND; knr.R = this.R; knr.SEQ = seq_builder(S, this.R.DB.Count); return knr; }
public override int Select0(int I) { if (this.AbsRankComp == null) { this.AbsRankComp = new ListGen<int> ((int i) => _Rank0_Abs (i), this.SuperBlocks.Length); this.RelRankComp = new ListGen<short> ((int i) => _Rank0_Rel (i), this.Blocks.Length); this.BitmapComp = new ListGen<uint> ((int i) => ~this.BitBlocks[i], this.BitBlocks.Count); } return this.SelectBackend (I, this.AbsRankComp, this.RelRankComp, this.BitmapComp); }
public IList<int> GetNotIdxPERM() { long n = this.Count; var gen = new ListGen<int> (delegate(int i) { var pos = this.Lens.Select0 (i + 1); // pos + 1 = rank0 + rank1 // rank1 = pos + 1 - rank0 = pos + 1 - (i - 1) = pos - i => symbol = rank1 - 1 var symbol = pos - i - 1; pos = this.Lens.Select1(symbol + 1); var rank0 = pos - symbol; return this.InvIndex[symbol].Select1(i - rank0 + 1); }, (int)n); return gen; }
public void Build(IBitStream B, short blockSize) { this.N = (int)B.CountBits; this.BlockSize = (short)blockSize; this.InitClasses(); this.Offsets = new BitStream32 (); IList<int> _L = new ListIFS (15, B); IList<int> L; if ((B.CountBits % 15) == 0) { L = _L; } else { int D = _L.Count; int C = 15 * D; var ctx = new BitStreamCtx(0); ctx.Seek(C); int last_block = (int)B.Read(((int)B.CountBits) - C, ctx); L = new ListGen<int>(delegate(int a) { if (a == D) { return last_block; } else { return _L[a]; } }, D+1); } this.AbsRank = new int[(int)Math.Ceiling(((float)L.Count) / this.BlockSize)]; this.AbsOffset = new int[ this.AbsRank.Count ]; int I = 0; int acc = 0; for (int i = 0; i < L.Count; i++) { var u = (short)L[i]; var klass = GetClass(u); this.EncodeClass(klass); if (i % this.BlockSize == 0) { this.AbsRank[I] = acc; this.AbsOffset[I] = (int)this.Offsets.CountBits; I++; } var numbits = NumBits[klass]; if (numbits > 0) { int offset = this.GetOffset (u, klass); this.Offsets.Write (offset, numbits); } acc += klass; } }
void HwangLinTwoLists(IList<int> S, int startS, int endS, IList<int> L, int startL, int endL, IList<int> Out) { int m = endS - startS; int n = endL - startL; int currStartL = startL; ListGen<int> Lsample = new ListGen<int>( (int iS) => L[iS * m + currStartL], (int)Math.Ceiling(n * 1.0 / m)); for (int i = startS; i < endS; i++) { int data = S[i]; int occPos; if (this.SampleSearch.Search(data, Lsample, out occPos, 0, Lsample.Count)) { // occPos++; Out.Add( data ); Lsample.Length -= occPos; currStartL += occPos * m; } else { // if occPos == 0: out of range if (occPos > 0) { occPos--; Lsample.Length -= occPos; currStartL += occPos * m; int currEndL = Math.Min(currStartL + m, endL); if (this.BlockSearch.Search(data, L, out occPos, currStartL, currEndL)) { Out.Add( data ); } } } } }