forked from aerospike/aerospike-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdt_context.go
91 lines (81 loc) · 2.92 KB
/
cdt_context.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright 2012-2019 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements WHICH ARE COMPATIBLE WITH THE APACHE LICENSE, VERSION 2.0.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http: *www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package aerospike
// CDTContext defines Nested CDT context. Identifies the location of nested list/map to apply the operation.
// for the current level.
// An array of CTX identifies location of the list/map on multiple
// levels on nesting.
type CDTContext struct {
id int
value Value
}
// CtxListIndex defines Lookup list by index offset.
// If the index is negative, the resolved index starts backwards from end of list.
// If an index is out of bounds, a parameter error will be returned.
// Examples:
// 0: First item.
// 4: Fifth item.
// -1: Last item.
// -3: Third to last item.
func CtxListIndex(index int) *CDTContext {
return &CDTContext{0x10, IntegerValue(index)}
}
// CtxListIndexCreate list with given type at index offset, given an order and pad.
func CtxListIndexCreate(index int, order ListOrderType, pad bool) *CDTContext {
return &CDTContext{0x10 | cdtListOrderFlag(order, pad), IntegerValue(index)}
}
// CtxListRank defines Lookup list by rank.
// 0 = smallest value
// N = Nth smallest value
// -1 = largest value
func CtxListRank(rank int) *CDTContext {
return &CDTContext{0x11, IntegerValue(rank)}
}
// CtxListValue defines Lookup list by value.
func CtxListValue(key Value) *CDTContext {
return &CDTContext{0x13, key}
}
// CtxMapIndex defines Lookup map by index offset.
// If the index is negative, the resolved index starts backwards from end of list.
// If an index is out of bounds, a parameter error will be returned.
// Examples:
// 0: First item.
// 4: Fifth item.
// -1: Last item.
// -3: Third to last item.
func CtxMapIndex(index int) *CDTContext {
return &CDTContext{0x20, IntegerValue(index)}
}
// CtxMapRank defines Lookup map by rank.
// 0 = smallest value
// N = Nth smallest value
// -1 = largest value
func CtxMapRank(rank int) *CDTContext {
return &CDTContext{0x21, IntegerValue(rank)}
}
// CtxMapKey defines Lookup map by key.
func CtxMapKey(key Value) *CDTContext {
return &CDTContext{0x22, key}
}
// Create map with given type at map key.
func CtxMapKeyCreate(key Value, order mapOrderType) *CDTContext {
return &CDTContext{0x22 | order.flag, key}
}
// CtxMapValue defines Lookup map by value.
func CtxMapValue(key Value) *CDTContext {
return &CDTContext{0x23, key}
}