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 IEnumerable <KeyWord> search(IBox box, KeyWord nw, IEnumerable <KeyWord> condition, MaxID maxId) { IEnumerator <KeyWord> cd = condition.GetEnumerator(); IEnumerator <KeyWord> r1 = null; KeyWord r1_con = null; long r1_id = -1; return(new Iterable <KeyWord>() { iterator = new EngineIterator <KeyWord>() { hasNext = () => { if (r1 != null && r1.MoveNext()) { return true; } while (cd.MoveNext()) { r1_con = cd.Current; if (r1_id == r1_con.getID()) { continue; } if (!nw.isLinked) { r1_id = r1_con.getID(); } r1 = search(box, nw, r1_con, maxId).GetEnumerator(); if (r1.MoveNext()) { return true; } } return false; }, next = () => { KeyWord k = r1.Current; k.previous = r1_con; return k; } } }); }
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; } } }); }