Coverage report: /development/source/library/com/dydra/gitlab/dydra-cgi/ffi/lisp/dydra-ndk/quad_cursor.lisp

KindCoveredAll%
expression0143 0.0
branch06 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 (in-package :dydra-ndk)
2
 
3
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
 
5
 (defctype size_t :ullong "std::size_t")
6
 
7
 ;; Quad cursors are opaque dydra::term_cursor structures allocated on the
8
 ;; foreign heap and referenced indirectly through a foreign pointer.
9
 (defctype quad-cursor :pointer
10
   "Quad cursor handle.")
11
 
12
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
14
 (defcfunwi ("dydra_quad_cursor_make" %%quad-cursor-make) quad-cursor
15
   (transaction-uuid (:pointer uuid))
16
   (graph-id term-id)
17
   (subject-id term-id)
18
   (predicate-id term-id)
19
   (object-id term-id)
20
   (flags :uint64))
21
 
22
 (defcfunwi ("dydra_quad_cursor_free" %%quad-cursor-free) :void
23
   (cursor quad-cursor))
24
 
25
 (defcfun ("dydra_quad_cursor_set_offset" %%quad-cursor-set-offset) :void
26
   (cursor quad-cursor)
27
   (offset size_t))
28
 
29
 (defcfun ("dydra_quad_cursor_set_limit" %%quad-cursor-set-limit) :void
30
   (cursor quad-cursor)
31
   (limit size_t))
32
 
33
 (defcfun ("dydra_quad_cursor_set_buffer" %%quad-cursor-set-buffer) :void
34
   (cursor quad-cursor)
35
   (count size_t))
36
 
37
 (defcfun ("dydra_quad_cursor_set_flags" %%quad-cursor-set-flags) :void
38
   (cursor quad-cursor)
39
   (flags :uint64))
40
 
41
 (defcfun ("dydra_quad_cursor_add_graph" %%quad-cursor-add-graph) :void
42
   (cursor quad-cursor)
43
   (graph-id term-id))
44
 
45
 (defcfun ("dydra_quad_cursor_set_graph" %%quad-cursor-set-graph) :void
46
   (cursor quad-cursor)
47
   (graph-id term-id))
48
 
49
 (defcfun ("dydra_quad_cursor_get_id" %%quad-cursor-get-id) :uint64
50
   (cursor quad-cursor))
51
 
52
 (defcfun ("dydra_quad_cursor_get_term" %%quad-cursor-get-term) term-id
53
   (cursor quad-cursor)
54
   (term-pos :uint))
55
 
56
 (defcfun ("dydra_quad_cursor_get_quad" %%quad-cursor-get-quad) (:pointer quad)
57
   (cursor quad-cursor))
58
 
59
 (defcfun ("dydra_quad_cursor_get_position" %%quad-cursor-get-position) size_t
60
   (cursor quad-cursor))
61
 
62
 (defcfun ("dydra_quad_cursor_open" %%quad-cursor-open) :void
63
   (cursor quad-cursor))
64
 
65
 (defcfun ("dydra_quad_cursor_close" %%quad-cursor-close) :void
66
   (cursor quad-cursor))
67
 
68
 (defcfun ("dydra_quad_cursor_count" %%quad-cursor-count) size_t
69
   (cursor quad-cursor))
70
 
71
 (defcfun ("dydra_quad_cursor_has_next" %%quad-cursor-has-next) :boolean
72
   (cursor quad-cursor))
73
 
74
 (defcfun ("dydra_quad_cursor_next" %%quad-cursor-next) :boolean
75
   (cursor quad-cursor))
76
 
77
 (defcfun ("dydra_quad_cursor_skip" %%quad-cursor-skip) size_t
78
   (cursor quad-cursor)
79
   (count size_t))
80
 
81
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
82
 
83
 (defun make-quad-cursor (transaction-uuid graph-id* subject-id predicate-id object-id
84
                          &key (distinct nil) (ordered t) (graph nil)
85
                               (offset nil) (limit nil) (buffer nil))
86
   "Creates a new transaction-scoped quad cursor, returning its handle."
87
   (declare (type foreign-pointer transaction-uuid)
88
            (type (or list fixnum) graph-id*)
89
            (type fixnum subject-id predicate-id object-id)
90
            (type boolean distinct ordered)
91
            (type (or fixnum null) graph)
92
            (type (or integer null) offset limit buffer))
93
   (let ((cursor (%%quad-cursor-make transaction-uuid
94
                                     (if (integerp graph-id*) graph-id* 0)
95
                                     subject-id predicate-id object-id
96
                                     (if (or distinct ordered) 1 0))))
97
     (when (listp graph-id*)
98
       (dolist (graph-id graph-id*)
99
         (%%quad-cursor-add-graph cursor graph-id)))
100
     (when graph  (%%quad-cursor-set-graph cursor graph))
101
     (when offset (%%quad-cursor-set-offset cursor offset))
102
     (when limit  (%%quad-cursor-set-limit cursor limit))
103
     (when buffer (%%quad-cursor-set-buffer cursor buffer))
104
     (%%quad-cursor-open cursor)
105
     cursor))
106
 
107
 (defun free-quad-cursor (cursor)
108
   (declare (type foreign-pointer cursor))
109
   (%%quad-cursor-free cursor))
110
 
111
 (defun quad-cursor-id (cursor)
112
   (declare (type foreign-pointer cursor))
113
   (%%quad-cursor-get-id cursor))
114
 
115
 (defun quad-cursor-term (cursor term-position)
116
   (declare (type foreign-pointer cursor)
117
            (type fixnum term-position))
118
   (%%quad-cursor-get-term cursor term-position))
119
 
120
 (defun quad-cursor-graph-id (cursor)
121
   (declare (type foreign-pointer cursor))
122
   (quad-cursor-term cursor 0))
123
 
124
 (defun quad-cursor-subject-id (cursor)
125
   (declare (type foreign-pointer cursor))
126
   (quad-cursor-term cursor 1))
127
 
128
 (defun quad-cursor-predicate-id (cursor)
129
   (declare (type foreign-pointer cursor))
130
   (quad-cursor-term cursor 2))
131
 
132
 (defun quad-cursor-object-id (cursor)
133
   (declare (type foreign-pointer cursor))
134
   (quad-cursor-term cursor 3))
135
 
136
 (defun quad-cursor-quad (cursor)
137
   (declare (type foreign-pointer cursor))
138
   (%%quad-cursor-get-quad cursor))
139
 
140
 (defun quad-cursor-position (cursor)
141
   (declare (type foreign-pointer cursor))
142
   (%%quad-cursor-get-position cursor))
143
 
144
 (defun quad-cursor-count (cursor)
145
   (declare (type foreign-pointer cursor))
146
   (%%quad-cursor-count cursor))
147
 
148
 (defun quad-cursor-close (cursor)
149
   (declare (type foreign-pointer cursor))
150
   (%%quad-cursor-close cursor))
151
 
152
 (defun quad-cursor-next (cursor)
153
   (declare (type foreign-pointer cursor))
154
   (%%quad-cursor-next cursor))
155
 
156
 (defun quad-cursor-skip (cursor &optional (count 1))
157
   (declare (type foreign-pointer cursor)
158
            (type integer count))
159
   (%%quad-cursor-skip cursor count))
160
 
161
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
162
 
163
 (defun print-quad-cursor (cursor &optional (stream *standard-output*))
164
   (declare (type foreign-pointer cursor))
165
   (print-unreadable-object (cursor stream :type nil :identity t)
166
     (format stream "DYDRA-NDK:QUAD-CURSOR #~s"
167
             (quad-cursor-id cursor))))
168
 
169
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170
 
171
 (defun count-matched-quads (transaction-uuid graph-id* subject-id predicate-id object-id
172
                             &key (offset nil) (limit nil))
173
   "Executes a transaction-scoped quad-pattern match, returning the matched quad count."
174
   (declare (type foreign-pointer transaction-uuid)
175
            (type (or list fixnum) graph-id*)
176
            (type fixnum subject-id predicate-id object-id)
177
            (type (or integer null) offset limit))
178
   (let* ((cursor (make-quad-cursor transaction-uuid graph-id* subject-id predicate-id object-id
179
                                    :distinct t :ordered nil :graph nil
180
                                    :offset offset :limit limit :buffer nil))
181
          (count (quad-cursor-count cursor)))
182
     (free-quad-cursor cursor)
183
     count))