static void insertToBox(IBox box, KeyWord kw, bool isRemove) { Binder binder; if (kw is KeyWordE) { binder = box["/E", kw.getKeyWord(), kw.getID(), kw.getPosition()]; } else { binder = box["/N", kw.getKeyWord(), kw.getID(), kw.getPosition()]; } if (isRemove) { binder.Delete(); } else { if (binder.TableName == "/E") { binder.Insert((KeyWordE)kw); } else { binder.Insert((KeyWordN)kw); } } }
private static IEnumerable <KeyWord> lessMatch(IBox box, KeyWord kw) { if (kw is KeyWordE) { return(box.Select <KeyWordE>("from /E where K<=? limit 0, 50", kw.getKeyWord())); } else { return(box.Select <KeyWordN>("from /N where K<=? limit 0, 50", kw.getKeyWord())); } }
private static IEnumerable <KeyWord> search(IBox box, KeyWord kw, KeyWord con, MaxID maxId) { String ql = kw is KeyWordE ? "from /E where K==? & I<=?" : "from /N where K==? & I<=?"; int linkPos = kw.isLinked ? (con.getPosition() + con.size() + (kw is KeyWordE ? 1 : 0)) : -1; long currentMaxId = long.MaxValue; KeyWord cache = null; IEnumerator <KeyWord> iter = null; bool isLinkEndMet = false; return(new Iterable <KeyWord>() { iterator = new EngineIterator <KeyWord>() { hasNext = () => { if (maxId.id == -1) { return false; } if (currentMaxId > (maxId.id + 1)) { currentMaxId = maxId.id; iter = kw is KeyWordE ? (IEnumerator <KeyWord>)box.Select <KeyWordE>(ql, kw.getKeyWord(), maxId.id).GetEnumerator() : box.Select <KeyWordN>(ql, kw.getKeyWord(), maxId.id).GetEnumerator(); } while (iter.MoveNext()) { cache = iter.Current; maxId.id = cache.getID(); currentMaxId = maxId.id; if (con != null && con.I != maxId.id) { return false; } if (isLinkEndMet) { continue; } if (linkPos == -1) { return true; } int cpos = cache.getPosition(); if (cpos > linkPos) { continue; } if (cpos == linkPos) { if (kw.isLinkedEnd) { isLinkEndMet = true; } return true; } return false; } maxId.id = -1; return false; }, next = () => { return cache; } } }); }