public virtual void Build(MetricDB db, int width, Random rand, Func<InvertedIndex,InvertedIndex> create_invertedindex = null, Func<int,object> get_item = null) { this.DB = db; this.Width = width; int len = this.DB.Count; int pc = len / 100 + 1; int numbits = width > 32 ? 32 : width; Plain64InvertedIndex table = new Plain64InvertedIndex (); table.Initialize (1 << numbits); int maxhash = 0; this.PreBuild (rand, this.DB [0]); for (int objID = 0; objID < len; objID++) { if (objID % pc == 0) { Console.WriteLine ("Advance: {0:0.00}%, docid: {1}, total: {2}", objID * 100.0 / len, objID, len); } int hash; if (get_item == null) { hash = this.ComputeHash (this.DB [objID]); } else { hash = this.ComputeHash (get_item (objID)); } table.AddItem(hash, objID); if (hash > maxhash) { maxhash = hash; } } table.Trim (maxhash + 1); if (create_invertedindex == null) { this.invindex = table; } else { this.invindex = create_invertedindex (table); } }
public static Plain64InvertedIndex Build(InvertedIndex invindex) { var I = new Plain64InvertedIndex (); for (int i = 0; i < invindex.Count; ++i) { I.Add (invindex[i]); } return I; }