Vector<String> HelpTopicEnumDeclModules() { Index<String> modmap; const HelpTopicInfoMap& map = HelpTopicMap(); for(int i = 0; i < map.GetCount(); i++) modmap.FindAdd(map[i].decl_module); Vector<String> mm = modmap.PickKeys(); Sort(mm, StdLess<String>()); return mm; }
void RichQtfParser::FinishOldTable() { FinishCell(); Index<int> pos; Vector<int> srow; RichTable& t = Table(); Tab& b = table.Top(); for(int i = 0; i < t.GetRows(); i++) { int& s = srow.Add(); s = 0; int nx = b.rown[i]; for(int j = 0; j < nx; j++) s += t.GetSpan(i, j).cx; int xn = 0; for(int j = 0; j < nx; j++) { pos.FindAdd(xn * 10000 / s); xn += t.GetSpan(i, j).cx; } } Vector<int> h = pos.PickKeys(); if(h.GetCount() == 0) Error("table"); Sort(h); pos = pick(h); pos.Add(10000); RichTable tab; tab.SetFormat(t.GetFormat()); for(int i = 0; i < pos.GetCount() - 1; i++) { tab.AddColumn(pos[i + 1] - pos[i]); } for(int i = 0; i < t.GetRows(); i++) { int s = srow[i]; int nx = b.rown[i]; int xn = 0; int xi = 0; for(int j = 0; j < nx; j++) { Size span = t.GetSpan(i, j); xn += span.cx; int nxi = pos.Find(xn * 10000 / s); tab.SetPick(i, xi, t.GetPick(i, j)); tab.SetFormat(i, xi, t.GetFormat(i, j)); tab.SetSpan(i, xi, max(span.cy - 1, 0), nxi - xi - 1); xi = nxi; } } table.Drop(); if(table.GetCount()) table.Top().text.CatPick(pick(tab)); else target.CatPick(pick(tab)); oldtab = false; }
Vector<int> HelpTopicEnumLang() { Index<int> lngmap; const HelpTopicInfoMap& map = HelpTopicMap(); for(int i = 0; i < map.GetCount(); i++) { const HelpTopicInfo& topic = map[i]; for(int l = 0; l < topic.language.GetCount(); l++) lngmap.FindAdd(topic.language[l]); } Vector<int> lng = lngmap.PickKeys(); Sort(lng); return lng; }
Vector<String> HelpTopicEnumSpace() { const HelpTopicInfoMap& map = HelpTopicMap(); Index<String> spaces; for(int i = 0; i < map.GetCount(); i++) { String space, nesting, topic; HelpParseDPP(map.GetKey(i), space, nesting, topic); spaces.FindAdd(space); } Vector<String> splist = spaces.PickKeys(); Sort(splist, StdLess<String>()); return splist; }
Vector<String> HelpTopicEnumNesting(String sp) { const HelpTopicInfoMap& map = HelpTopicMap(); Index<String> nest; for(int i = 0; i < map.GetCount(); i++) { String space, nesting, topic; HelpParseDPP(map.GetKey(i), space, nesting, topic); if(IsNull(sp) || sp == space) nest.FindAdd(nesting); } Vector<String> nelist = nest.PickKeys(); Sort(nelist, StdLess<String>()); return nelist; }
Vector<String> Workspace::GetAllAccepts(int pk) const { Index<String> accepts; Index<int> pkg; pkg.Add(pk); for(int i = 0; i < pkg.GetCount(); i++) { const Package& p = package[pkg[i]]; FindAppend(accepts, p.accepts); for(int u = 0; u < p.uses.GetCount(); u++) { int f = package.Find(UnixPath(p.uses[u].text)); if(f >= 0) pkg.FindAdd(f); } } return accepts.PickKeys(); }
Vector<String> MakeBuild::GetAllLibraries(const Workspace& wspc, int index, const VectorMap<String, String>& bm, String mainparam, Host& host, Builder& builder) { // Warning: This does not seem to do what it is supposed to do... Vector<String> uses = GetAllUses(wspc, index); uses.Add(wspc[index]); Index<String> libraries; for(int i = 0; i < uses.GetCount(); i++) { int f = wspc.package.Find(UnixPath(uses[i])); if(f >= 0) { const Package& pk = wspc.package[f]; Index<String> config = PackageConfig(wspc, f, bm, mainparam, host, builder); Vector<String> pklibs = Split(Gather(pk.library, config.GetKeys()), ' '); FindAppend(libraries, pklibs); } } return libraries.PickKeys(); }
Vector<String> HelpTopicEnumTextFolders() { Index<String> out; const HelpTopicInfoMap& map = HelpTopicMap(); for(int i = 0; i < map.GetCount(); i++) { String drl = map.GetKey(i); String space, nesting, topic; HelpParseDPP(drl, space, nesting, topic); const HelpTopicInfo& info = map[i]; String folder = GetTextFolder(nesting, info.decl_module, info.text_folder); if(out.Find(folder) < 0) { out.Add(folder); LLOG("HelpTopicSave: folder = " << folder); } } Vector<String> list = out.PickKeys(); Sort(list, StdLess<String>()); return list; }
void IndexTutorial() { /// .`Index` /// `Index` is the the foundation of all U++ associative operations and is one of defining /// features of U++. /// `Index` is a container very similar to the plain `Vector` (it is random access array of /// elements with fast addition at the end) with one additional feature - it is able to fast /// retrieve position of element with required value using `Find` method: Index<String> ndx; ndx.Add("alfa"); ndx.Add("beta"); ndx.Add("gamma"); ndx.Add("delta"); ndx.Add("kappa"); DUMP(ndx); DUMP(ndx.Find("beta")); /// If element is not present in `Index`, `Find` returns a negative value: DUMP(ndx.Find("something")); /// Any element can be replaced using `Set` method: ndx.Set(1, "alfa"); DUMP(ndx); /// If there are more elements with the same value, they can be iterated using `FindNext` /// method: int fi = ndx.Find("alfa"); while(fi >= 0) { DUMP(fi); fi = ndx.FindNext(fi); } /// `FindAdd` method retrieves position of element like `Find`, but if element is not /// present in `Index`, it is added: DUMP(ndx.FindAdd("one")); DUMP(ndx.FindAdd("two")); DUMP(ndx.FindAdd("three")); DUMP(ndx.FindAdd("two")); DUMP(ndx.FindAdd("three")); DUMP(ndx.FindAdd("one")); /// Removing elements from random access sequence tends to be expensive, that is why rather /// than remove, `Index` supports `Unlink` and `UnlinkKey` operations, which retain the /// element in `Index` but make it invisible for `Find` operation: ndx.Unlink(2); ndx.UnlinkKey("kappa"); DUMP(ndx.Find(ndx[2])); DUMP(ndx.Find("kappa")); /// You can test whether element at given position is unlinked using `IsUnlinked` method DUMP(ndx.IsUnlinked(1)); DUMP(ndx.IsUnlinked(2)); /// Unlinked positions can be reused by `Put` method: ndx.Put("foo"); DUMP(ndx); DUMP(ndx.Find("foo")); /// You can also remove all unlinked elements from `Index` using `Sweep` method: ndx.Sweep(); DUMP(ndx); /// Operations directly removing or inserting elements of Index are expensive, but /// available too: ndx.Remove(1); DUMP(ndx); /// ndx.RemoveKey("two"); DUMP(ndx); /// ndx.Insert(0, "insert"); DUMP(ndx); /// PickKeys operation allows you to obtain Vector of elements of Index in low /// constant time operation (while destroying source Index) Vector<String> d = ndx.PickKeys(); DUMP(d); /// Pick-assigning `Vector` to `Index` is supported as well: d[0] = "test"; ndx = pick(d); DUMP(ndx); /// }
Vector<int> RichTxt::GetAllLanguages() const { Index<int> all; GetAllLanguages(all); return all.PickKeys(); }