summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMichael Cahill <michael.cahill@wiredtiger.com>2011-10-07 16:42:40 +1100
committerMichael Cahill <michael.cahill@wiredtiger.com>2011-10-07 16:42:40 +1100
commit6a3cec072fedbf73569d7a07924b9f2df30a1000 (patch)
treea0786028ae05b341053e407f4a159f4cf8566571 /ext
parent2856fecda7ed7b52d1f9466a6d7898c6cf02348e (diff)
downloadmongo-6a3cec072fedbf73569d7a07924b9f2df30a1000.tar.gz
Add a collator extension, include in test/format testing.
closes #118
Diffstat (limited to 'ext')
-rw-r--r--ext/collators/reverse/Makefile.am4
-rw-r--r--ext/collators/reverse/reverse_collator.c39
2 files changed, 43 insertions, 0 deletions
diff --git a/ext/collators/reverse/Makefile.am b/ext/collators/reverse/Makefile.am
new file mode 100644
index 00000000000..33e52907692
--- /dev/null
+++ b/ext/collators/reverse/Makefile.am
@@ -0,0 +1,4 @@
+INCLUDES = -I$(top_builddir) -I$(top_srcdir)/src/include
+
+lib_LTLIBRARIES = reverse_collator.la
+reverse_collator_la_LDFLAGS = -avoid-version -module
diff --git a/ext/collators/reverse/reverse_collator.c b/ext/collators/reverse/reverse_collator.c
new file mode 100644
index 00000000000..9a8a5eb59e7
--- /dev/null
+++ b/ext/collators/reverse/reverse_collator.c
@@ -0,0 +1,39 @@
+#include <errno.h>
+#include <string.h>
+
+#include <wiredtiger_ext.h>
+
+WT_EXTENSION_API *wt_api;
+
+#define __UNUSED(v) ((void)(v))
+
+static int
+collate_reverse(WT_COLLATOR *collator, WT_SESSION *session,
+ const WT_ITEM *k1, const WT_ITEM *k2, int *cmp)
+{
+ size_t len;
+
+ __UNUSED(collator);
+ __UNUSED(session);
+
+ len = (k1->size < k2->size) ? k1->size : k2->size;
+ if ((*cmp = memcmp(k2->data, k1->data, len)) == 0)
+ *cmp = ((int)k1->size - (int)k2->size);
+ return (0);
+}
+
+static WT_COLLATOR reverse_collator = { collate_reverse };
+
+int
+wiredtiger_extension_init(
+ WT_SESSION *session, WT_EXTENSION_API *api, const char *config)
+{
+ WT_CONNECTION *conn;
+
+ __UNUSED(config);
+
+ wt_api = api;
+ conn = session->connection;
+
+ return (conn->add_collator(conn, "reverse", &reverse_collator, NULL));
+}