-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_t.go
602 lines (569 loc) · 22.8 KB
/
key_t.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
//////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2018-2022 YottaDB LLC and/or its subsidiaries. //
// All rights reserved. //
// //
// This source code contains the intellectual property //
// of its copyright holder(s), and is made available //
// under a license. If you do not know the terms of //
// the license, please stop and do not read further. //
// //
//////////////////////////////////////////////////////////////////
package yottadb
import (
"io"
"os"
"runtime"
"sync/atomic"
"unsafe"
)
// #include "libyottadb.h"
import "C"
// KeyT defines a database key including varname and optional subscripts. Because this structure's contents contain
// pointers to C allocated storage, this structure is NOT safe for concurrent access.
type KeyT struct {
Varnm *BufferT
Subary *BufferTArray
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Data manipulation methods for KeyT
//
////////////////////////////////////////////////////////////////////////////////////////////////////
// Alloc is a STAPI method to allocate both pieces of the KeyT according to the supplied parameters.
//
// Invoke Varnm.Alloc(varSiz) and SubAry.Alloc(numSubs, subSiz)
//
// Parameters:
// varSiz - Length of buffer for varname (current var max is 31).
// numSubs - Number of subscripts to supply (current subscript max is 31).
// subSiz - Length of the buffers for subscript values.
func (key *KeyT) Alloc(varSiz, numSubs, subSiz uint32) {
var buffertary BufferTArray
var buffer BufferT
printEntry("KeyT.Alloc()")
if nil == key {
panic("YDB: *KeyT receiver of Alloc() cannot be nil")
}
key.Varnm = &buffer
key.Varnm.Alloc(varSiz)
key.Subary = &buffertary
key.Subary.Alloc(numSubs, subSiz)
}
// Dump is a STAPI method to dump the contents of the KeyT structure.
//
// Invoke Varnm.Dump() and SubAry.Dump().
func (key *KeyT) Dump() {
printEntry("KeyT.Dump()")
if nil == key {
panic("YDB: *KeyT receiver of Dump() cannot be nil")
}
key.DumpToWriter(os.Stdout)
}
// DumpToWriter dumps a textual representation of this key to the writer.
func (key *KeyT) DumpToWriter(writer io.Writer) {
if nil == key {
panic("YDB: *KeyT receiver of DumpWriter() cannot be nil")
}
if nil != key.Varnm {
key.Varnm.DumpToWriter(writer)
}
if nil != key.Subary {
key.Subary.DumpToWriter(writer)
}
}
// Free is a STAPI method to free both pieces of the KeyT structure.
//
// Invoke Varnm.Free() and SubAry.Free().
func (key *KeyT) Free() {
printEntry("KeyT.Free()")
if nil != key { // Ignore if no struct passed
key.Varnm.Free()
key.Subary.Free()
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Simple (Threaded) API methods for KeyT
//
////////////////////////////////////////////////////////////////////////////////////////////////////
// DataST is a STAPI method to determine the status of a given node and its successors.
//
// Matching DataE(), DataST() returns the result of ydb_data_st(). In the event an error is returned, the return value
// is unspecified.
func (key *KeyT) DataST(tptoken uint64, errstr *BufferT) (uint32, error) {
var retval C.uint
var cbuft *C.ydb_buffer_t
printEntry("KeyT.DataST()")
if nil == key {
panic("YDB: *KeyT receiver of DataST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_data_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()), subbuftary, &retval)
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return uint32(retval), err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(errstr)
return uint32(retval), nil
}
// DeleteST is a STAPI method to delete a node and perhaps its successors depending on the value of deltype.
//
// Matching DeleteE(), DeleteST() wraps ydb_delete_st() to delete a local or global variable node or (sub)tree, with a value of
// YDB_DEL_NODE for deltype specifying that only the node should be deleted, leaving the (sub)tree untouched, and a value
// of YDB_DEL_TREE specifying that the node as well as the (sub)tree are to be deleted.
func (key *KeyT) DeleteST(tptoken uint64, errstr *BufferT, deltype int) error {
var cbuft *C.ydb_buffer_t
printEntry("KeyT.DeleteST()")
if nil == key {
panic("YDB: *KeyT receiver of DeleteST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_delete_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()), subbuftary,
C.int(deltype))
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(errstr)
return nil
}
// ValST is a STAPI method to fetch the given node returning its value in retval.
//
// Matching ValE(), ValST() wraps ydb_get_st() to return the value at the referenced global or local variable node, or
// intrinsic special variable, in the buffer referenced by the BufferT structure referenced by retval.
//
// If ydb_get_st() returns an error such as GVUNDEF, INVSVN, LVUNDEF, the method makes no changes to the structures under retval
// and returns the error. If the length of the data to be returned exceeds retval.getLenAlloc(), the method sets the len_used` of
// the C.ydb_buffer_t referenced by retval to the required length, and returns an INVSTRLEN error. Otherwise, it copies the data
// to the buffer referenced by the retval.buf_addr, and sets retval.lenUsed to its length.
func (key *KeyT) ValST(tptoken uint64, errstr *BufferT, retval *BufferT) error {
var cbuft *C.ydb_buffer_t
printEntry("KeyT.ValST()")
if nil == key {
panic("YDB: *KeyT receiver of ValST() cannot be nil")
}
if (1 != atomic.LoadUint32(&ydbInitialized)) && (1 != atomic.LoadUint32(&inInit)) {
// Run initialization but only if we haven't run it before AND we aren't already in initializeYottaDB()
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_get_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()), subbuftary,
retval.getCPtr())
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(retval)
runtime.KeepAlive(errstr)
return nil
}
// IncrST is a STAPI method to increment a given node and return the new value.
//
// Matching IncrE(), IncrST() wraps ydb_incr_st() to atomically increment the referenced global or local variable node
// coerced to a number, with incr coerced to a number. It stores the result in the node and also returns it through
// the BufferT structure referenced by retval.
//
// If ydb_incr_st() returns an error such as NUMOFLOW, INVSTRLEN, the method makes no changes to the structures under retval and
// returns the error. If the length of the data to be returned exceeds retval.lenAlloc, the method sets the len_used
// of the C.ydb_buffer_t referenced by retval to the required length, and returns an INVSTRLEN error.
// Otherwise, it copies the data to the buffer referenced by the retval.buf_addr, sets retval.lenUsed to its length.
//
// With a nil value for incr, the default increment is 1. Note that the value of the empty string coerced to an integer is zero.
func (key *KeyT) IncrST(tptoken uint64, errstr *BufferT, incr, retval *BufferT) error {
var cbuft, incrcbuft *C.ydb_buffer_t
printEntry("KeyT.IncrST()")
if nil == key {
panic("YDB: *KeyT receiver of IncrST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
subbuftary := subgobuftary.getCPtr()
if nil != incr {
incrcbuft = incr.getCPtr()
}
rc := C.ydb_incr_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()), subbuftary, incrcbuft,
retval.getCPtr())
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(retval)
runtime.KeepAlive(incr)
runtime.KeepAlive(errstr)
return nil
}
// LockDecrST is a STAPI method to decrement the lock-count of a given lock node.
//
// Matching LockDecrE(), LockDecrST() wraps ydb_lock_decr_st() to decrement the count of the lock name
// referenced, releasing it if the count goes to zero or ignoring the invocation if the process does not hold the lock.
func (key *KeyT) LockDecrST(tptoken uint64, errstr *BufferT) error {
var cbuft *C.ydb_buffer_t
printEntry("KeyT.LockDecrST()")
if nil == key {
panic("YDB: *KeyT receiver of LockDecrST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_lock_decr_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()), subbuftary)
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(errstr)
return nil
}
// LockIncrST is a STAPI method to increment the lock-count of a given node lock with the given timeout in nano-seconds.
//
// Matching LockIncrE(), LockIncrST() wraps ydb_lock_incr_st() to attempt to acquire the referenced lock
// resource name without releasing any locks the process already holds.
//
// If the process already holds the named lock resource, the method increments its count and returns.
// If timeoutNsec exceeds YDB_MAX_TIME_NSEC, the method returns with an error return TIME2LONG.
// If it is able to aquire the lock resource within timeoutNsec nanoseconds, it returns holding the lock, otherwise it returns
// LOCK_TIMEOUT. If timeoutNsec is zero, the method makes exactly one attempt to acquire the lock.
func (key *KeyT) LockIncrST(tptoken uint64, errstr *BufferT, timeoutNsec uint64) error {
var cbuft *C.ydb_buffer_t
printEntry("KeyT.LockIncrST()")
if nil == key {
panic("YDB: *KeyT receiver of LockIncrST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_lock_incr_st(C.uint64_t(tptoken), cbuft, C.ulonglong(timeoutNsec), vargobuft,
C.int(subgobuftary.ElemUsed()), subbuftary)
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(errstr)
return nil
}
// NodeNextST is a STAPI method to return the next subscripted node for the given global - the node logically following the
// specified node (returns *BufferTArray).
//
// Matching NodeNextE(), NodeNextST() wraps ydb_node_next_st() to facilitate depth first traversal of a local or global variable tree.
//
// If there is a next node:
//
// If the number of subscripts of that next node exceeds next.elemAlloc, the method sets next.elemUsed to
// the number of subscripts required, and returns an INSUFFSUBS error. In this case the elemUsed is greater than elemAlloc.
// If one of the C.ydb_buffer_t structures referenced by next (call the first or only element n) has insufficient space for
// the corresponding subscript, the method sets next.elemUsed to n, and the len_alloc of that C.ydb_buffer_t structure to the actual space
// required. The method returns an INVSTRLEN error. In this case the len_used of that structure is greater than its len_alloc.
// Otherwise, it sets the structure next to reference the subscripts of that next node, and next.elemUsed to the number of subscripts.
//
// If the node is the last in the tree, the method returns the NODEEND error, making no changes to the structures below next.
func (key *KeyT) NodeNextST(tptoken uint64, errstr *BufferT, next *BufferTArray) error {
var nextElemPtr *uint32
var nextElemUsed, dummyElemUsed uint32
var nextSubaryPtr, cbuft *C.ydb_buffer_t
printEntry("KeyT.NodeNextST()")
if nil == key {
panic("YDB: *KeyT receiver of NodeNextST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
// The output buffer does not need to be allocated at this point though it may error in ydb_node_next_s() if not.
if nil != next {
nextElemUsed = next.ElemAlloc() // Set all elements of output array available for output
nextElemPtr = &nextElemUsed
nextSubaryPtr = next.getCPtr()
} else {
nextElemPtr = &dummyElemUsed
nextSubaryPtr = nil
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_node_next_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()), subbuftary,
(*C.int)(unsafe.Pointer(nextElemPtr)), nextSubaryPtr)
if nil != next { // If return area supplied, set the subscript count in the output array (always)
next.cbuftary.elemUsed = nextElemUsed
}
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(next)
runtime.KeepAlive(errstr)
return nil
}
// NodePrevST is a STAPI method to return the previous subscripted node for the given global - the node logically previous
// to the specified node (returns *BufferTArray).
//
// Matching NodePrevE(), NodePrevST() wraps ydb_node_previous_st() to facilitate reverse depth first traversal of a local or global variable tree.
//
// If there is a previous node:
//
// If the number of subscripts of that previous node exceeds prev.elemAlloc, the method sets prev.elemUsed to
// the number of subscripts required, and returns an INSUFFSUBS error. In this case the elemUsed is greater than elemAlloc.
// If one of the C.ydb_buffer_t structures referenced by prev (call the first or only element n) has insufficient space for
// the corresponding subscript, the method sets prev.elemUsed to n, and the len_alloc of that C.ydb_buffer_t structure to the actual space
// required. The method returns an INVSTRLEN error. In this case the len_used of that structure is greater than its len_alloc.
// Otherwise, it sets the structure prev to reference the subscripts of that prev node, and prev.elemUsed to the number of subscripts.
//
// If the node is the first in the tree, the method returns the NODEEND error making no changes to the structures below prev.
func (key *KeyT) NodePrevST(tptoken uint64, errstr *BufferT, prev *BufferTArray) error {
var prevElemPtr *uint32
var prevElemUsed, dummyElemUsed uint32
var prevSubaryPtr, cbuft *C.ydb_buffer_t
printEntry("KeyT.NodePrevST()")
if nil == key {
panic("YDB: *KeyT receiver of NodePrevST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
// The output buffer does not need to be allocated at this point though it may error in ydb_node_previous_s() if not.
if nil != prev {
prevElemUsed = prev.ElemAlloc() // Set all elements of output array available for output
prevElemPtr = &prevElemUsed
prevSubaryPtr = prev.getCPtr()
} else {
prevElemPtr = &dummyElemUsed
prevSubaryPtr = nil
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_node_previous_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()),
subbuftary, (*C.int)(unsafe.Pointer(prevElemPtr)), prevSubaryPtr)
if nil != prev { // If return area supplied, set the subscript count in the output array (always)
prev.cbuftary.elemUsed = prevElemUsed
}
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(prev)
runtime.KeepAlive(errstr)
return nil
}
// SetValST is a STAPI method to set the given value into the given node (glvn or SVN).
//
// Matching SetE(), at the referenced local or global variable node, or the intrinsic special variable, SetValST() wraps
// ydb_set_st() to set the value specified by val.
func (key *KeyT) SetValST(tptoken uint64, errstr *BufferT, value *BufferT) error {
var cbuft *C.ydb_buffer_t
printEntry("KeyT.SetValST()")
if nil == key {
panic("YDB: *KeyT receiver of SetValST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
cbuftary := subgobuftary.getCPtr()
rc := C.ydb_set_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()), cbuftary, value.getCPtr())
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(value)
runtime.KeepAlive(errstr)
return nil
}
// SubNextST is a STAPI method to return the next subscript following the specified node.
//
// Matching SubNextE(), SubNextST() wraps ydb_subscript_next_st() to facilitate breadth-first traversal of a
// local or global variable sub-tree.
//
// At the level of the last subscript, if there is a next subscript with a node and/or a subtree:
//
// If the length of that next subscript exceeds sub.len_alloc, the method sets sub.len_used to the
// actual length of that subscript, and returns an INVSTRLEN error. In this case sub.len_used is greater than
// sub.len_alloc. Otherwise, it copies that subscript to the buffer referenced by
// sub.buf_addr, and sets sub.len_used to its length.
//
// If there is no next node or subtree at that level of the subtree, the method returns the NODEEND error.
func (key *KeyT) SubNextST(tptoken uint64, errstr *BufferT, retval *BufferT) error {
var cbuft *C.ydb_buffer_t
printEntry("KeyT.SubNextST()")
if nil == key {
panic("YDB: *KeyT receiver of SubNextST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_subscript_next_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()),
subbuftary, retval.getCPtr())
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(retval)
runtime.KeepAlive(errstr)
return nil
}
// SubPrevST is a STAPI method to return the previous subscript following the specified node.
//
// SubPrevST() wraps ydb_subscript_previous_st() to facilitate reverse breadth-first traversal of a local or global variable sub-tree.
//
// At the level of the last subscript, if there is a previous subscript with a node and/or a subtree:
//
// If the length of that previous subscript exceeds sub.len_alloc, the method sets sub.len_used to the
// actual length of that subscript, and returns an INVSTRLEN error. In this case sub.len_used is greater than
// sub.len_alloc. Otherwise, it copies that subscript to the buffer referenced by sub.buf_addr, and sets buf.len_used to its length.
//
// If there is no previous node or subtree at that level of the subtree, the method returns the NODEEND error.
func (key *KeyT) SubPrevST(tptoken uint64, errstr *BufferT, retval *BufferT) error {
var cbuft *C.ydb_buffer_t
printEntry("KeyT.SubPrevST()")
if nil == key {
panic("YDB: *KeyT receiver of SubPrevST() cannot be nil")
}
if 1 != atomic.LoadUint32(&ydbInitialized) {
initializeYottaDB()
}
if nil != errstr {
cbuft = errstr.getCPtr()
}
vargobuft := key.Varnm.getCPtr()
if (nil == vargobuft) || (nil == vargobuft.buf_addr) || (0 == vargobuft.len_used) {
panic("YDB: KeyT varname is not allocated, is nil, or has a 0 length")
}
subgobuftary := key.Subary
if nil == subgobuftary {
panic("YDB: KeyT Subary is nil")
}
subbuftary := subgobuftary.getCPtr()
rc := C.ydb_subscript_previous_st(C.uint64_t(tptoken), cbuft, vargobuft, C.int(subgobuftary.ElemUsed()),
subbuftary, retval.getCPtr())
if YDB_OK != rc {
err := NewError(tptoken, errstr, int(rc))
return err
}
runtime.KeepAlive(key) // Make sure key hangs around through the YDB call
runtime.KeepAlive(retval)
runtime.KeepAlive(errstr)
return nil
}