lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [39/54] [abbrv] git commit: refs/heads/sortex_ptr_only - Implement Compare_To() for RawPosting.
Date Sat, 26 Apr 2014 23:12:09 GMT
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/e6d1963a
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e6d1963a
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e6d1963a

Branch: refs/heads/sortex_ptr_only
Commit: e6d1963ab2e5b9a5c394ff3639a4559cc5b20e0b
Parents: d4282a9
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Wed Jan 2 17:43:16 2013 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sat Apr 26 08:56:54 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/Posting/RawPosting.c   | 22 ++++++++++++++++++++++
 core/Lucy/Index/Posting/RawPosting.cfh |  3 +++
 2 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/e6d1963a/core/Lucy/Index/Posting/RawPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RawPosting.c b/core/Lucy/Index/Posting/RawPosting.c
index 5f5e8d4..d02cae2 100644
--- a/core/Lucy/Index/Posting/RawPosting.c
+++ b/core/Lucy/Index/Posting/RawPosting.c
@@ -51,6 +51,28 @@ RawPost_Destroy_IMP(RawPosting *self) {
     THROW(ERR, "Illegal attempt to destroy RawPosting object");
 }
 
+int32_t
+RawPost_Compare_To_IMP(RawPosting *self, Obj *other) {
+    RawPostingIVARS *const ivars = RawPost_IVARS(self);
+    RawPostingIVARS *const ovars = RawPost_IVARS((RawPosting*)other);
+    const size_t my_len    = ivars->content_len;
+    const size_t other_len = ovars->content_len;
+    const size_t len       = my_len < other_len ? my_len : other_len;
+    int32_t comparison = memcmp(ivars->blob, ovars->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)other_len);
+
+        // Break ties by doc id.
+        if (comparison == 0) {
+            comparison = ivars->doc_id - ovars->doc_id;
+        }
+    }
+
+    return comparison;
+}
+
 uint32_t
 RawPost_Get_RefCount_IMP(RawPosting* self) {
     UNUSED_VAR(self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/e6d1963a/core/Lucy/Index/Posting/RawPosting.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RawPosting.cfh b/core/Lucy/Index/Posting/RawPosting.cfh
index b57c285..2fe0286 100644
--- a/core/Lucy/Index/Posting/RawPosting.cfh
+++ b/core/Lucy/Index/Posting/RawPosting.cfh
@@ -59,6 +59,9 @@ class Lucy::Index::RawPosting nickname RawPost
     uint32_t
     Dec_RefCount(RawPosting* self);
 
+    public int32_t
+    Compare_To(RawPosting *self, Obj *other);
+
     /** Throws an error.
      */
     public void


Mime
View raw message