@based/db 0.0.63 → 0.0.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/darwin_aarch64/include/selva/db.h +30 -4
- package/dist/lib/darwin_aarch64/include/selva/fields.h +36 -24
- package/dist/lib/darwin_aarch64/include/selva/hll.h +5 -3
- package/dist/lib/darwin_aarch64/include/selva/membar.h +23 -0
- package/dist/lib/darwin_aarch64/include/selva/types.h +1 -1
- package/dist/lib/darwin_aarch64/include/selva/worker_ctx.h +19 -3
- package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
- package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
- package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
- package/dist/lib/darwin_aarch64/libnode-v24.node +0 -0
- package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
- package/dist/lib/darwin_aarch64/libxxhash.dylib +0 -0
- package/dist/lib/linux_aarch64/include/selva/db.h +30 -4
- package/dist/lib/linux_aarch64/include/selva/fields.h +36 -24
- package/dist/lib/linux_aarch64/include/selva/hll.h +5 -3
- package/dist/lib/linux_aarch64/include/selva/membar.h +23 -0
- package/dist/lib/linux_aarch64/include/selva/types.h +1 -1
- package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +19 -3
- package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
- package/dist/lib/linux_aarch64/libnode-v24.node +0 -0
- package/dist/lib/linux_aarch64/libselva.so +0 -0
- package/dist/lib/linux_x86_64/include/selva/db.h +30 -4
- package/dist/lib/linux_x86_64/include/selva/fields.h +36 -24
- package/dist/lib/linux_x86_64/include/selva/hll.h +5 -3
- package/dist/lib/linux_x86_64/include/selva/membar.h +23 -0
- package/dist/lib/linux_x86_64/include/selva/types.h +1 -1
- package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +19 -3
- package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
- package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
- package/dist/lib/linux_x86_64/libnode-v24.node +0 -0
- package/dist/lib/linux_x86_64/libselva.so +0 -0
- package/dist/src/client/flushModify.js +2 -2
- package/dist/src/client/modify/create.js +1 -1
- package/dist/src/client/modify/delete.js +2 -2
- package/dist/src/client/modify/expire.js +1 -1
- package/dist/src/client/modify/fixed.js +1 -1
- package/dist/src/client/modify/update.js +1 -1
- package/dist/src/client/query/BasedDbQuery.d.ts +3 -2
- package/dist/src/client/query/BasedDbQuery.js +16 -0
- package/dist/src/client/query/aggregates/types.d.ts +2 -1
- package/dist/src/client/query/read/read.js +6 -3
- package/dist/src/client/query/subscription/index.js +6 -1
- package/dist/src/client/query/validation.d.ts +3 -0
- package/dist/src/client/query/validation.js +9 -0
- package/dist/src/hooks.js +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/native.d.ts +5 -2
- package/dist/src/native.js +16 -5
- package/dist/src/server/DbWorker.d.ts +2 -2
- package/dist/src/server/DbWorker.js +3 -1
- package/dist/src/server/index.d.ts +1 -0
- package/dist/src/server/index.js +2 -1
- package/dist/src/server/migrate/index.js +2 -1
- package/dist/src/server/migrate/worker.js +3 -0
- package/dist/src/server/save.js +5 -5
- package/dist/src/server/start.js +2 -2
- package/package.json +2 -2
- package/dist/lib/darwin_aarch64/include/selva/find.h +0 -47
- package/dist/lib/darwin_aarch64/include/selva/queue_r.h +0 -190
- package/dist/lib/darwin_aarch64/include/selva/traverse.h +0 -65
- package/dist/lib/linux_aarch64/include/selva/find.h +0 -47
- package/dist/lib/linux_aarch64/include/selva/queue_r.h +0 -190
- package/dist/lib/linux_aarch64/include/selva/traverse.h +0 -65
- package/dist/lib/linux_x86_64/include/selva/find.h +0 -47
- package/dist/lib/linux_x86_64/include/selva/queue_r.h +0 -190
- package/dist/lib/linux_x86_64/include/selva/traverse.h +0 -65
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*******************************************************************************
|
|
3
|
-
* @file queue_r.h
|
|
4
|
-
* @author Olli Vanhoja
|
|
5
|
-
* @brief Thread-safe queue
|
|
6
|
-
* @section LICENSE
|
|
7
|
-
* Copyright (c) 2020-2021, 2023, 2025 SAULX
|
|
8
|
-
* Copyright (c) 2013, 2015, 2016 Olli Vanhoja <olli.vanhoja@cs.helsinki.fi>
|
|
9
|
-
* Copyright (c) 2012, 2013 Ninjaware Oy,
|
|
10
|
-
* Olli Vanhoja <olli.vanhoja@ninjaware.fi>
|
|
11
|
-
* All rights reserved.
|
|
12
|
-
*
|
|
13
|
-
* Redistribution and use in source and binary forms, with or without
|
|
14
|
-
* modification, are permitted provided that the following conditions are met:
|
|
15
|
-
*
|
|
16
|
-
* 1. Redistributions of source code must retain the above copyright notice,
|
|
17
|
-
* this list of conditions and the following disclaimer.
|
|
18
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
19
|
-
* this list of conditions and the following disclaimer in the documentation
|
|
20
|
-
* and/or other materials provided with the distribution.
|
|
21
|
-
*
|
|
22
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
23
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
24
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
25
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
26
|
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
27
|
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
28
|
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
29
|
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
30
|
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
31
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
32
|
-
* POSSIBILITY OF SUCH DAMAGE.
|
|
33
|
-
*
|
|
34
|
-
* SPDX-License-Identifier: BSD-2-Clause
|
|
35
|
-
*******************************************************************************
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @addtogroup queue_r
|
|
40
|
-
* @{
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
#pragma once
|
|
44
|
-
|
|
45
|
-
#include <stddef.h>
|
|
46
|
-
#include "selva/_export.h"
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Queue control block.
|
|
50
|
-
*/
|
|
51
|
-
typedef struct queue_cb {
|
|
52
|
-
void * data; /*!< Pointer to the data array used for queue. */
|
|
53
|
-
size_t b_size; /*!< Block size in bytes. */
|
|
54
|
-
size_t a_len; /*!< Array length. */
|
|
55
|
-
size_t m_write; /*!< Write index. */
|
|
56
|
-
size_t m_read; /*!< Read index. */
|
|
57
|
-
} queue_cb_t;
|
|
58
|
-
|
|
59
|
-
#define QUEUE_INITIALIZER(data_array, block_size, array_size) \
|
|
60
|
-
(struct queue_cb){ \
|
|
61
|
-
.data = (data_array), \
|
|
62
|
-
.b_size = (block_size), \
|
|
63
|
-
.a_len = (array_size / block_size), \
|
|
64
|
-
.m_write = 0, \
|
|
65
|
-
.m_read = 0, \
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Create a new queue control block.
|
|
70
|
-
* Initializes a new queue control block and returns it as a value.
|
|
71
|
-
* @param data_array an array where the actual queue data is stored.
|
|
72
|
-
* @param block_size the size of single data block/struct/data type in
|
|
73
|
-
* data_array in bytes.
|
|
74
|
-
* @param array_size the size of the data_array in bytes.
|
|
75
|
-
* @return a new queue_cb_t queue control block structure.
|
|
76
|
-
*/
|
|
77
|
-
SELVA_EXPORT
|
|
78
|
-
queue_cb_t queue_create(void * data_array, size_t block_size,
|
|
79
|
-
size_t array_size)
|
|
80
|
-
__attribute__((pure, access(read_only, 1, 3)));
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Push an element to the queue.
|
|
84
|
-
* @param cb is a pointer to the queue control block.
|
|
85
|
-
* @param element the new element to be copied.
|
|
86
|
-
* @return 0 if queue is already full; otherwise operation was succeed.
|
|
87
|
-
* @note element is always copied to the queue, so it is safe to remove the
|
|
88
|
-
* original data after a push.
|
|
89
|
-
*/
|
|
90
|
-
SELVA_EXPORT
|
|
91
|
-
int queue_push(queue_cb_t * cb, const void * element)
|
|
92
|
-
__attribute__((access(read_write, 1)));
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Allocate an element from the queue.
|
|
96
|
-
* @param cb is a pointer to the queue control block.
|
|
97
|
-
* @return A pointer to the element in the queue.
|
|
98
|
-
*/
|
|
99
|
-
SELVA_EXPORT
|
|
100
|
-
void * queue_alloc_get(queue_cb_t * cb)
|
|
101
|
-
__attribute__((access(read_write, 1)));
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Commit previous allocation from the queue.
|
|
105
|
-
* @note queue_push() should not be called between calls to queue_alloc_get()
|
|
106
|
-
* and queue_alloc_commit().
|
|
107
|
-
*/
|
|
108
|
-
SELVA_EXPORT
|
|
109
|
-
void queue_alloc_commit(queue_cb_t * cb)
|
|
110
|
-
__attribute__((access(read_write, 1)));
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Pop an element from the queue.
|
|
114
|
-
* @param cb is a pointer to the queue control block.
|
|
115
|
-
* @param element is the location where element is copied to from the queue.
|
|
116
|
-
* @return 0 if queue is empty; otherwise operation was succeed.
|
|
117
|
-
*/
|
|
118
|
-
SELVA_EXPORT
|
|
119
|
-
int queue_pop(queue_cb_t * cb, void * element)
|
|
120
|
-
__attribute__((access(read_write, 1)));
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Peek an element from the queue.
|
|
124
|
-
* @param cb is a pointer to the queue control block.
|
|
125
|
-
* @param element is the location where element is copied to from the queue.
|
|
126
|
-
* @return 0 if queue is empty; otherwise operation was succeed.
|
|
127
|
-
*/
|
|
128
|
-
SELVA_EXPORT
|
|
129
|
-
int queue_peek(queue_cb_t * cb, void ** element)
|
|
130
|
-
__attribute__((access(read_only, 1), access(write_only, 2)));
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Skip n number of elements in the queue.
|
|
134
|
-
* @param cb is a pointer to the queue control block.
|
|
135
|
-
* @return Returns the number of elements skipped.
|
|
136
|
-
*/
|
|
137
|
-
SELVA_EXPORT
|
|
138
|
-
int queue_skip(queue_cb_t * cb, size_t n)
|
|
139
|
-
__attribute__((access(read_write, 1)));
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Clear the queue.
|
|
143
|
-
* This operation is considered safe when committed from the push end thread.
|
|
144
|
-
* @param cb is a pointer to the queue control block.
|
|
145
|
-
*/
|
|
146
|
-
SELVA_EXPORT
|
|
147
|
-
void queue_clear_from_push_end(queue_cb_t * cb)
|
|
148
|
-
__attribute__((access(read_write, 1)));
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Clear the queue.
|
|
152
|
-
* This operation is considered safe when committed from the pop end thread.
|
|
153
|
-
* @param cb is a pointer to the queue control block.
|
|
154
|
-
*/
|
|
155
|
-
SELVA_EXPORT
|
|
156
|
-
void queue_clear_from_pop_end(queue_cb_t * cb)
|
|
157
|
-
__attribute__((access(read_write, 1)));
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Check if the queue is empty.
|
|
161
|
-
* @param cb is a pointer to the queue control block.
|
|
162
|
-
* @return 0 if the queue is not empty.
|
|
163
|
-
*/
|
|
164
|
-
SELVA_EXPORT
|
|
165
|
-
int queue_isempty(const queue_cb_t * cb)
|
|
166
|
-
__attribute__((access(read_only, 1)));
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Check if the queue is full.
|
|
170
|
-
* @param cb is a pointer to the queue control block.
|
|
171
|
-
* @return 0 if the queue is not full.
|
|
172
|
-
*/
|
|
173
|
-
SELVA_EXPORT
|
|
174
|
-
int queue_isfull(const queue_cb_t * cb)
|
|
175
|
-
__attribute__((access(read_only, 1)));
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Seek queue.
|
|
179
|
-
* @param cb is a pointer to the queue control block.
|
|
180
|
-
* @param i index.
|
|
181
|
-
* @param[in] element returned element.
|
|
182
|
-
* @return 0 if failed; otherwise succeed.
|
|
183
|
-
*/
|
|
184
|
-
SELVA_EXPORT
|
|
185
|
-
int seek(const queue_cb_t * cb, size_t i, void * element)
|
|
186
|
-
__attribute__((access(read_only, 1), access(write_only, 3)));
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @}
|
|
190
|
-
*/
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024 SAULX
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "selva/_export.h"
|
|
8
|
-
|
|
9
|
-
struct SelvaNode;
|
|
10
|
-
struct SelvaDb;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Traversal metadata for child/adjacent nodes.
|
|
14
|
-
* Note that SelvaTraversalOrder expects this to be copyable.
|
|
15
|
-
*/
|
|
16
|
-
struct SelvaTraversalMetadata {
|
|
17
|
-
const struct SelvaFields *edge_data; /*!< Edge metadata. */
|
|
18
|
-
long long depth;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
#define SELVA_TRAVERSAL_ABORT (-2)
|
|
22
|
-
#define SELVA_TRAVERSAL_STOP (-1)
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Called for each node found during a traversal.
|
|
26
|
-
* @param node a pointer to the node.
|
|
27
|
-
* @param arg a pointer to node_arg give in SelvaTraversalCallback structure.
|
|
28
|
-
*/
|
|
29
|
-
typedef int (*SelvaTraversalNodeCallback)(
|
|
30
|
-
struct SelvaDb *db,
|
|
31
|
-
const struct SelvaTraversalMetadata *metadata,
|
|
32
|
-
struct SelvaNode *node,
|
|
33
|
-
void *arg);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Callback descriptor used for traversals.
|
|
37
|
-
*/
|
|
38
|
-
struct SelvaTraversalParam {
|
|
39
|
-
/**
|
|
40
|
-
* Called for each orphan head in the hierarchy.
|
|
41
|
-
*/
|
|
42
|
-
SelvaTraversalNodeCallback head_cb;
|
|
43
|
-
void *head_arg;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Called for each node in the hierarchy.
|
|
47
|
-
*/
|
|
48
|
-
SelvaTraversalNodeCallback node_cb;
|
|
49
|
-
void *node_arg;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Called for each child of current node.
|
|
53
|
-
*/
|
|
54
|
-
SelvaTraversalNodeCallback child_cb;
|
|
55
|
-
void *child_arg;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
SELVA_EXPORT
|
|
59
|
-
int selva_traverse_field_bfs(
|
|
60
|
-
struct SelvaDb *db,
|
|
61
|
-
struct SelvaNode *head,
|
|
62
|
-
const struct SelvaTraversalParam *cb);
|
|
63
|
-
|
|
64
|
-
SELVA_EXPORT
|
|
65
|
-
int selva_traverse_type(struct SelvaDb *db, struct SelvaTypeEntry *te, SelvaTraversalNodeCallback node_cb, void *node_arg);
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024 SAULX
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "selva/_export.h"
|
|
8
|
-
#include "selva/types.h"
|
|
9
|
-
#include "selva/traverse.h"
|
|
10
|
-
|
|
11
|
-
struct SelvaFindParam {
|
|
12
|
-
SelvaTraversalNodeCallback node_cb;
|
|
13
|
-
void *node_arg;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Traverse field selector.
|
|
17
|
-
*/
|
|
18
|
-
const struct FindFields {
|
|
19
|
-
uint8_t len;
|
|
20
|
-
struct {
|
|
21
|
-
node_type_t type;
|
|
22
|
-
field_t field;
|
|
23
|
-
} __packed data[];
|
|
24
|
-
} __packed *fields;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Skip the first n nodes in the traversal.
|
|
28
|
-
* This happens before filtering.
|
|
29
|
-
*/
|
|
30
|
-
ssize_t skip;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Skip the first n - 1 results.
|
|
34
|
-
* This skipping is executed on the final result set.
|
|
35
|
-
* 0 for no offset.
|
|
36
|
-
*/
|
|
37
|
-
ssize_t offset;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Limit the number of results.
|
|
41
|
-
* -1 for no limit (inf).
|
|
42
|
-
*/
|
|
43
|
-
ssize_t limit;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
SELVA_EXPORT
|
|
47
|
-
int selva_find(struct SelvaDb *db, struct SelvaNode *node, const struct SelvaFindParam *param);
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*******************************************************************************
|
|
3
|
-
* @file queue_r.h
|
|
4
|
-
* @author Olli Vanhoja
|
|
5
|
-
* @brief Thread-safe queue
|
|
6
|
-
* @section LICENSE
|
|
7
|
-
* Copyright (c) 2020-2021, 2023, 2025 SAULX
|
|
8
|
-
* Copyright (c) 2013, 2015, 2016 Olli Vanhoja <olli.vanhoja@cs.helsinki.fi>
|
|
9
|
-
* Copyright (c) 2012, 2013 Ninjaware Oy,
|
|
10
|
-
* Olli Vanhoja <olli.vanhoja@ninjaware.fi>
|
|
11
|
-
* All rights reserved.
|
|
12
|
-
*
|
|
13
|
-
* Redistribution and use in source and binary forms, with or without
|
|
14
|
-
* modification, are permitted provided that the following conditions are met:
|
|
15
|
-
*
|
|
16
|
-
* 1. Redistributions of source code must retain the above copyright notice,
|
|
17
|
-
* this list of conditions and the following disclaimer.
|
|
18
|
-
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
19
|
-
* this list of conditions and the following disclaimer in the documentation
|
|
20
|
-
* and/or other materials provided with the distribution.
|
|
21
|
-
*
|
|
22
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
23
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
24
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
25
|
-
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
26
|
-
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
27
|
-
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
28
|
-
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
29
|
-
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
30
|
-
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
31
|
-
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
32
|
-
* POSSIBILITY OF SUCH DAMAGE.
|
|
33
|
-
*
|
|
34
|
-
* SPDX-License-Identifier: BSD-2-Clause
|
|
35
|
-
*******************************************************************************
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @addtogroup queue_r
|
|
40
|
-
* @{
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
#pragma once
|
|
44
|
-
|
|
45
|
-
#include <stddef.h>
|
|
46
|
-
#include "selva/_export.h"
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Queue control block.
|
|
50
|
-
*/
|
|
51
|
-
typedef struct queue_cb {
|
|
52
|
-
void * data; /*!< Pointer to the data array used for queue. */
|
|
53
|
-
size_t b_size; /*!< Block size in bytes. */
|
|
54
|
-
size_t a_len; /*!< Array length. */
|
|
55
|
-
size_t m_write; /*!< Write index. */
|
|
56
|
-
size_t m_read; /*!< Read index. */
|
|
57
|
-
} queue_cb_t;
|
|
58
|
-
|
|
59
|
-
#define QUEUE_INITIALIZER(data_array, block_size, array_size) \
|
|
60
|
-
(struct queue_cb){ \
|
|
61
|
-
.data = (data_array), \
|
|
62
|
-
.b_size = (block_size), \
|
|
63
|
-
.a_len = (array_size / block_size), \
|
|
64
|
-
.m_write = 0, \
|
|
65
|
-
.m_read = 0, \
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Create a new queue control block.
|
|
70
|
-
* Initializes a new queue control block and returns it as a value.
|
|
71
|
-
* @param data_array an array where the actual queue data is stored.
|
|
72
|
-
* @param block_size the size of single data block/struct/data type in
|
|
73
|
-
* data_array in bytes.
|
|
74
|
-
* @param array_size the size of the data_array in bytes.
|
|
75
|
-
* @return a new queue_cb_t queue control block structure.
|
|
76
|
-
*/
|
|
77
|
-
SELVA_EXPORT
|
|
78
|
-
queue_cb_t queue_create(void * data_array, size_t block_size,
|
|
79
|
-
size_t array_size)
|
|
80
|
-
__attribute__((pure, access(read_only, 1, 3)));
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Push an element to the queue.
|
|
84
|
-
* @param cb is a pointer to the queue control block.
|
|
85
|
-
* @param element the new element to be copied.
|
|
86
|
-
* @return 0 if queue is already full; otherwise operation was succeed.
|
|
87
|
-
* @note element is always copied to the queue, so it is safe to remove the
|
|
88
|
-
* original data after a push.
|
|
89
|
-
*/
|
|
90
|
-
SELVA_EXPORT
|
|
91
|
-
int queue_push(queue_cb_t * cb, const void * element)
|
|
92
|
-
__attribute__((access(read_write, 1)));
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Allocate an element from the queue.
|
|
96
|
-
* @param cb is a pointer to the queue control block.
|
|
97
|
-
* @return A pointer to the element in the queue.
|
|
98
|
-
*/
|
|
99
|
-
SELVA_EXPORT
|
|
100
|
-
void * queue_alloc_get(queue_cb_t * cb)
|
|
101
|
-
__attribute__((access(read_write, 1)));
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Commit previous allocation from the queue.
|
|
105
|
-
* @note queue_push() should not be called between calls to queue_alloc_get()
|
|
106
|
-
* and queue_alloc_commit().
|
|
107
|
-
*/
|
|
108
|
-
SELVA_EXPORT
|
|
109
|
-
void queue_alloc_commit(queue_cb_t * cb)
|
|
110
|
-
__attribute__((access(read_write, 1)));
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Pop an element from the queue.
|
|
114
|
-
* @param cb is a pointer to the queue control block.
|
|
115
|
-
* @param element is the location where element is copied to from the queue.
|
|
116
|
-
* @return 0 if queue is empty; otherwise operation was succeed.
|
|
117
|
-
*/
|
|
118
|
-
SELVA_EXPORT
|
|
119
|
-
int queue_pop(queue_cb_t * cb, void * element)
|
|
120
|
-
__attribute__((access(read_write, 1)));
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Peek an element from the queue.
|
|
124
|
-
* @param cb is a pointer to the queue control block.
|
|
125
|
-
* @param element is the location where element is copied to from the queue.
|
|
126
|
-
* @return 0 if queue is empty; otherwise operation was succeed.
|
|
127
|
-
*/
|
|
128
|
-
SELVA_EXPORT
|
|
129
|
-
int queue_peek(queue_cb_t * cb, void ** element)
|
|
130
|
-
__attribute__((access(read_only, 1), access(write_only, 2)));
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Skip n number of elements in the queue.
|
|
134
|
-
* @param cb is a pointer to the queue control block.
|
|
135
|
-
* @return Returns the number of elements skipped.
|
|
136
|
-
*/
|
|
137
|
-
SELVA_EXPORT
|
|
138
|
-
int queue_skip(queue_cb_t * cb, size_t n)
|
|
139
|
-
__attribute__((access(read_write, 1)));
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Clear the queue.
|
|
143
|
-
* This operation is considered safe when committed from the push end thread.
|
|
144
|
-
* @param cb is a pointer to the queue control block.
|
|
145
|
-
*/
|
|
146
|
-
SELVA_EXPORT
|
|
147
|
-
void queue_clear_from_push_end(queue_cb_t * cb)
|
|
148
|
-
__attribute__((access(read_write, 1)));
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Clear the queue.
|
|
152
|
-
* This operation is considered safe when committed from the pop end thread.
|
|
153
|
-
* @param cb is a pointer to the queue control block.
|
|
154
|
-
*/
|
|
155
|
-
SELVA_EXPORT
|
|
156
|
-
void queue_clear_from_pop_end(queue_cb_t * cb)
|
|
157
|
-
__attribute__((access(read_write, 1)));
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Check if the queue is empty.
|
|
161
|
-
* @param cb is a pointer to the queue control block.
|
|
162
|
-
* @return 0 if the queue is not empty.
|
|
163
|
-
*/
|
|
164
|
-
SELVA_EXPORT
|
|
165
|
-
int queue_isempty(const queue_cb_t * cb)
|
|
166
|
-
__attribute__((access(read_only, 1)));
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Check if the queue is full.
|
|
170
|
-
* @param cb is a pointer to the queue control block.
|
|
171
|
-
* @return 0 if the queue is not full.
|
|
172
|
-
*/
|
|
173
|
-
SELVA_EXPORT
|
|
174
|
-
int queue_isfull(const queue_cb_t * cb)
|
|
175
|
-
__attribute__((access(read_only, 1)));
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Seek queue.
|
|
179
|
-
* @param cb is a pointer to the queue control block.
|
|
180
|
-
* @param i index.
|
|
181
|
-
* @param[in] element returned element.
|
|
182
|
-
* @return 0 if failed; otherwise succeed.
|
|
183
|
-
*/
|
|
184
|
-
SELVA_EXPORT
|
|
185
|
-
int seek(const queue_cb_t * cb, size_t i, void * element)
|
|
186
|
-
__attribute__((access(read_only, 1), access(write_only, 3)));
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @}
|
|
190
|
-
*/
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024 SAULX
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "selva/_export.h"
|
|
8
|
-
|
|
9
|
-
struct SelvaNode;
|
|
10
|
-
struct SelvaDb;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Traversal metadata for child/adjacent nodes.
|
|
14
|
-
* Note that SelvaTraversalOrder expects this to be copyable.
|
|
15
|
-
*/
|
|
16
|
-
struct SelvaTraversalMetadata {
|
|
17
|
-
const struct SelvaFields *edge_data; /*!< Edge metadata. */
|
|
18
|
-
long long depth;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
#define SELVA_TRAVERSAL_ABORT (-2)
|
|
22
|
-
#define SELVA_TRAVERSAL_STOP (-1)
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Called for each node found during a traversal.
|
|
26
|
-
* @param node a pointer to the node.
|
|
27
|
-
* @param arg a pointer to node_arg give in SelvaTraversalCallback structure.
|
|
28
|
-
*/
|
|
29
|
-
typedef int (*SelvaTraversalNodeCallback)(
|
|
30
|
-
struct SelvaDb *db,
|
|
31
|
-
const struct SelvaTraversalMetadata *metadata,
|
|
32
|
-
struct SelvaNode *node,
|
|
33
|
-
void *arg);
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Callback descriptor used for traversals.
|
|
37
|
-
*/
|
|
38
|
-
struct SelvaTraversalParam {
|
|
39
|
-
/**
|
|
40
|
-
* Called for each orphan head in the hierarchy.
|
|
41
|
-
*/
|
|
42
|
-
SelvaTraversalNodeCallback head_cb;
|
|
43
|
-
void *head_arg;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Called for each node in the hierarchy.
|
|
47
|
-
*/
|
|
48
|
-
SelvaTraversalNodeCallback node_cb;
|
|
49
|
-
void *node_arg;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Called for each child of current node.
|
|
53
|
-
*/
|
|
54
|
-
SelvaTraversalNodeCallback child_cb;
|
|
55
|
-
void *child_arg;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
SELVA_EXPORT
|
|
59
|
-
int selva_traverse_field_bfs(
|
|
60
|
-
struct SelvaDb *db,
|
|
61
|
-
struct SelvaNode *head,
|
|
62
|
-
const struct SelvaTraversalParam *cb);
|
|
63
|
-
|
|
64
|
-
SELVA_EXPORT
|
|
65
|
-
int selva_traverse_type(struct SelvaDb *db, struct SelvaTypeEntry *te, SelvaTraversalNodeCallback node_cb, void *node_arg);
|