Updated Branches: refs/heads/sortex_ptr_only [created] 7310e7706
Implement Compare_To() for RawPosting. Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/d586080f Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/d586080f Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/d586080f Branch: refs/heads/sortex_ptr_only Commit: d586080f437a35925e1435cac0de728c1eeb4467 Parents: df55233 Author: Marvin Humphrey <[email protected]> Authored: Wed Jan 2 17:43:16 2013 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Fri Jan 4 13:12:59 2013 -0800 ---------------------------------------------------------------------- core/Lucy/Index/Posting/RawPosting.c | 21 +++++++++++++++++++++ core/Lucy/Index/Posting/RawPosting.cfh | 3 +++ 2 files changed, 24 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/d586080f/core/Lucy/Index/Posting/RawPosting.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/Posting/RawPosting.c b/core/Lucy/Index/Posting/RawPosting.c index 589547f..3671866 100644 --- a/core/Lucy/Index/Posting/RawPosting.c +++ b/core/Lucy/Index/Posting/RawPosting.c @@ -51,6 +51,27 @@ RawPost_destroy(RawPosting *self) { THROW(ERR, "Illegal attempt to destroy RawPosting object"); } +int32_t +RawPost_compare_to(RawPosting *self, Obj *other) { + RawPosting *twin = (RawPosting*)other; + const size_t my_len = self->content_len; + const size_t twin_len = twin->content_len; + const size_t len = my_len < twin_len ? my_len : twin_len; + int32_t comparison = memcmp(self->blob, twin->blob, len); + + if (comparison == 0) { + // If a is a substring of b, it's less than b, so return a neg num. + comparison = (int32_t)((int64_t)my_len - (int64_t)twin_len); + + // Break ties by doc id. + if (comparison == 0) { + comparison = self->doc_id - twin->doc_id; + } + } + + return comparison; +} + uint32_t RawPost_get_refcount(RawPosting* self) { UNUSED_VAR(self); http://git-wip-us.apache.org/repos/asf/lucy/blob/d586080f/core/Lucy/Index/Posting/RawPosting.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/Posting/RawPosting.cfh b/core/Lucy/Index/Posting/RawPosting.cfh index aab5846..c6f1305 100644 --- a/core/Lucy/Index/Posting/RawPosting.cfh +++ b/core/Lucy/Index/Posting/RawPosting.cfh @@ -59,6 +59,9 @@ class Lucy::Index::RawPosting cnick RawPost uint32_t Dec_RefCount(RawPosting* self); + public int32_t + Compare_To(RawPosting *self, Obj *other); + /** Throws an error. */ public void
