-
Notifications
You must be signed in to change notification settings - Fork 9
/
subspace.clj
68 lines (54 loc) · 1.96 KB
/
subspace.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(ns me.vedang.clj-fdb.subspace.subspace
(:refer-clojure :exclude [contains? range get])
(:require [me.vedang.clj-fdb.tuple.tuple :as ftup])
(:import com.apple.foundationdb.Range
com.apple.foundationdb.subspace.Subspace
com.apple.foundationdb.tuple.Tuple))
(defn ^Subspace create
"Constructor for a subspace formed with the specified prefix Tuple."
([prefix]
(cond
(vector? prefix) (Subspace. (ftup/create prefix))
(instance? Tuple prefix) (Subspace. ^Tuple prefix)
:else (throw (IllegalArgumentException.
"Don't know how to create Subspace from input"))))
([] (Subspace.)))
(defn contains?
"Tests whether the specified key starts with this Subspace's prefix,
indicating that the Subspace logically contains key."
[^Subspace s ^"[B" key]
(.contains s key))
(defn ^Range range
"Gets a Range respresenting all keys strictly in the Subspace.
If a tuple is passed, gets a Range representing all keys in the
Subspace strictly starting with the specified Tuple."
([^Subspace s ^Tuple t]
(.range s t))
([^Subspace s]
(.range s)))
(defn ^"[B" pack
"Gets the key encoding the prefix used for this Subspace.
If a tuple is passed, key encoding is suffixed with passed tuple. If
a non-tuple is passed, it is converted to a tuple and used as a
suffix."
([^Subspace s]
(.pack s))
([^Subspace s t]
(cond
(instance? Tuple t) (.pack s ^Tuple t)
(vector? t) (.pack s ^Tuple (ftup/create t))
:else (.pack s ^Tuple (ftup/from t)))))
(defn ^Tuple unpack
"Gets the Tuple encoded by the given key, with this Subspace's
prefix Tuple and raw prefix removed."
[^Subspace s ^"[B" key]
(.unpack s key))
(defn ^"[B" get-key
"Gets the key encoding the prefix used for this Subspace."
[^Subspace s]
(.getKey s))
(defn ^"[B" get
"Gets a new subspace which is equivalent to this subspace with its
prefix Tuple extended by the specified Tuple."
[^Subspace s ^Tuple t]
(.get s t))