int TStrUtil::SplitOnCh(TChA& ChA, TVec<char *>& WrdV, const char& Ch, const bool& SkipEmpty) { WrdV.Clr(false); WrdV.Add(ChA.CStr()); for (char *c = (char *) ChA.CStr(); *c; c++) { if (*c == Ch) { *c = 0; if (SkipEmpty && ! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); } WrdV.Add(c+1); } } if (SkipEmpty && ! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); } return WrdV.Len(); }
void TIndex::TQmGixSumItemHandler<TQmGixItem>::Merge(TVec<TQmGixItem>& ItemV, const bool& IsLocal) const { if (ItemV.Empty()) { return; } // nothing to do in this case if (!ItemV.IsSorted()) { ItemV.Sort(); } // sort if not yet sorted // merge counts int LastItemN = 0; bool ZeroP = false; for (int ItemN = 1; ItemN < ItemV.Len(); ItemN++) { if (ItemV[ItemN].Key != ItemV[ItemN - 1].Key) { LastItemN++; ItemV[LastItemN] = ItemV[ItemN]; } else { ItemV[LastItemN].Dat += ItemV[ItemN].Dat; } ZeroP = ZeroP || (ItemV[LastItemN].Dat <= 0); } // remove items with zero count if (ZeroP) { int LastIndN = 0; for (int ItemN = 0; ItemN < LastItemN + 1; ItemN++) { const TQmGixItem& Item = ItemV[ItemN]; if (Item.Dat.Val > 0 || (IsLocal && Item.Dat.Val < 0)) { ItemV[LastIndN] = Item; LastIndN++; } else if (Item.Dat.Val < 0) { TEnv::Error->OnStatusFmt("Warning: negative item count %d:%d!", (int)Item.Key, (int)Item.Dat); } } ItemV.Reserve(ItemV.Reserved(), LastIndN); } else { ItemV.Reserve(ItemV.Reserved(), LastItemN + 1); } }
TFltIntIntTr FindMxQEdge() { while (true) { if (MxQHeap.Empty()) { break; } const TFltIntIntTr TopQ = MxQHeap.PopHeap(); if (! CmtyQH.IsKey(TopQ.Val2) || ! CmtyQH.IsKey(TopQ.Val3)) { continue; } if (TopQ.Val1!=CmtyQH.GetDat(TopQ.Val2).GetMxQ() && TopQ.Val1!=CmtyQH.GetDat(TopQ.Val3).GetMxQ()) { continue; } return TopQ; } return TFltIntIntTr(-1, -1, -1); }
int TStrUtil::SplitWords(TChA& ChA, TVec<char *>& WrdV, const bool& SplitOnWs) { WrdV.Clr(false); WrdV.Add(ChA.CStr()); for (char *c = (char *) ChA.CStr(); *c; c++) { if ((SplitOnWs && *c == ' ') || (! SplitOnWs && ! TCh::IsAlNum(*c))) { *c = 0; if (! WrdV.Empty() && strlen(WrdV.Last()) == 0) { WrdV.DelLast(); } WrdV.Add(c+1); } } return WrdV.Len(); }