You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2017/07/07 20:39:41 UTC

[04/14] qpid-dispatch git commit: DISPATCH-760: Add prefix search functions that use iterator pointers

DISPATCH-760: Add prefix search functions that use iterator pointers


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/7f650d8f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/7f650d8f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/7f650d8f

Branch: refs/heads/master
Commit: 7f650d8f9f3106942201b0b6ddc7eb4fe434a9a9
Parents: cf2c76a
Author: Chuck Rolke <cr...@redhat.com>
Authored: Fri Jun 30 12:30:35 2017 -0400
Committer: Chuck Rolke <cr...@redhat.com>
Committed: Fri Jul 7 10:38:14 2017 -0400

----------------------------------------------------------------------
 include/qpid/dispatch/iterator.h | 23 +++++++++++++++
 src/iterator.c                   | 53 +++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7f650d8f/include/qpid/dispatch/iterator.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/iterator.h b/include/qpid/dispatch/iterator.h
index f3641bc..9a965df 100644
--- a/include/qpid/dispatch/iterator.h
+++ b/include/qpid/dispatch/iterator.h
@@ -283,6 +283,18 @@ bool qd_iterator_equal(qd_iterator_t *iter, const unsigned char *string);
 bool qd_iterator_prefix(qd_iterator_t *iter, const char *prefix);
 
 /**
+ * Return true iff the prefix string matches the characters addressed by ptr.
+ * This function ignores octets beyond the length of the prefix.
+ * Caller's pointer is held constant.
+ *
+ * @param ptr buffer chain cursor holding message bytes
+ * @param skip AMQP housekeeping bytes to skip over before finding the incoming string
+ * @param prefix the prefix to be matched
+ * @return true if all bytes of prefix match bytes in user string
+ */
+bool qd_iterator_prefix_ptr(const qd_iterator_pointer_t *ptr, uint32_t skip, const char *prefix);
+
+/**
  * Copy the iterator's view into buffer up to a maximum of n bytes.  Cursor is
  * advanced by the number of bytes copied. There is no trailing '\0' added.
  * @return number of bytes copied.
@@ -406,6 +418,17 @@ void qd_iterator_hash_view_segments(qd_iterator_t *iter);
  */
 bool qd_iterator_next_segment(qd_iterator_t *iter, uint32_t *hash);
 
+/**
+ * Get an iterator's cursor details.
+ * Exposes iter's buffer, cursor, and remaining values.
+ *
+ * @param iter iter that still has data in its view.
+ * @param ptr Pointer object which is to receive cursor position
+ */
+void qd_iterator_get_view_cursor(
+    const qd_iterator_t   *iter,
+    qd_iterator_pointer_t *ptr);
+
 /** @} */
 /** @} */
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7f650d8f/src/iterator.c
----------------------------------------------------------------------
diff --git a/src/iterator.c b/src/iterator.c
index 99c5800..c456d16 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -648,6 +648,59 @@ bool qd_iterator_prefix(qd_iterator_t *iter, const char *prefix)
 }
 
 
+// bare bones copy of field_iterator_move_cursor with no field/view baggage
+void iterator_pointer_move_cursor(qd_iterator_pointer_t *ptr, uint32_t length)
+{
+    uint32_t count = length > ptr->remaining ? ptr->remaining : length;
+
+    while (count) {
+        uint32_t remaining = qd_buffer_cursor(ptr->buffer) - ptr->cursor;
+        remaining = remaining > count ? count : remaining;
+        ptr->cursor += remaining;
+        ptr->remaining -= remaining;
+        count -= remaining;
+        if (ptr->cursor == qd_buffer_cursor(ptr->buffer)) {
+            ptr->buffer = ptr->buffer->next;
+            if (ptr->buffer == 0) {
+                ptr->remaining = 0;
+                ptr->cursor = 0;
+                break;
+            } else {
+                ptr->cursor = qd_buffer_base(ptr->buffer);
+            }
+        }
+    }
+}
+
+
+// bare bones copy of qd_iterator_prefix with no iterator baggage
+bool qd_iterator_prefix_ptr(const qd_iterator_pointer_t *ptr, uint32_t skip, const char *prefix)
+{
+    if (!ptr)
+        return false;
+
+    qd_iterator_pointer_t lptr;
+    *&lptr = *ptr;
+
+    iterator_pointer_move_cursor(&lptr, skip);
+
+    unsigned char *c = (unsigned char*) prefix;
+
+    while(*c && lptr.remaining) {
+        unsigned char ic = *lptr.cursor;
+
+        if (*c != ic)
+            break;
+        c++;
+
+        iterator_pointer_move_cursor(&lptr, 1);
+        lptr.remaining -= 1;
+    }
+
+    return *c == 0;
+}
+
+
 int qd_iterator_length(const qd_iterator_t *iter)
 {
     return iter ? iter->annotation_length + iter->view_start_pointer.remaining : 0;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org