Jazz 1.25.+
Loading...
Searching...
No Matches
kind.h
1/* Jazz (c) 2018-2025 kaalam.ai (The Authors of Jazz), using (under the same license):
2
3 1. Biomodelling - The AATBlockQueue class (c) Jacques BasaldĂșa, 2009-2012 licensed
4 exclusively for the use in the Jazz server software.
5
6 Copyright 2009-2012 Jacques BasaldĂșa
7
8 2. BBVA - Jazz: A lightweight analytical web server for data-driven applications.
9
10 Copyright 2016-2017 Banco Bilbao Vizcaya Argentaria, S.A.
11
12 This product includes software developed at
13
14 BBVA (https://www.bbva.com/)
15
16 3. LMDB, Copyright 2011-2017 Howard Chu, Symas Corp. All rights reserved.
17
18 Licensed under http://www.OpenLDAP.org/license.html
19
20
21 Licensed under the Apache License, Version 2.0 (the "License");
22 you may not use this file except in compliance with the License.
23 You may obtain a copy of the License at
24
25 http://www.apache.org/licenses/LICENSE-2.0
26
27 Unless required by applicable law or agreed to in writing, software
28 distributed under the License is distributed on an "AS IS" BASIS,
29 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License for the specific language governing permissions and
31 limitations under the License.
32*/
33
34
35#include "src/jazz_elements/block.h"
36
37#ifdef CATCH_TEST
38#ifndef INCLUDED_JAZZ_CATCH2
39#define INCLUDED_JAZZ_CATCH2
40
41#include "src/catch2/catch.hpp"
42
43#endif
44#endif
45
46
47#ifndef INCLUDED_JAZZ_ELEMENTS_KIND
48#define INCLUDED_JAZZ_ELEMENTS_KIND
49
50
51namespace jazz_elements
52{
53
83class Kind : public Block {
84
85 public:
86
95 inline char *item_name(int idx) {
96 if (idx < 0 || idx >= size)
97 return nullptr;
98
99 return reinterpret_cast<char *>(&p_string_buffer()->buffer[tensor.cell_item[idx].name]);
100 }
101
108 inline int index(pChar name) {
109 for (int idx = 0; idx < size; idx++) {
110 if (strcmp(reinterpret_cast<char *>(&p_string_buffer()->buffer[tensor.cell_item[idx].name]), name) == 0)
111 return idx;
112 }
113 return -1;
114 }
115
121 inline void dimensions(Dimensions &dims) {
122 for (int i = 0; i < size; i++) {
123 ItemHeader *p_it_hea = &tensor.cell_item[i];
124
125 for (int j = 0; j < p_it_hea->rank; j++) {
126 int k = p_it_hea->dim[j];
127
128 if (k < 0) {
129 char *pt = (&p_string_buffer()->buffer[-k]);
130
131 dims.insert(std::string(pt));
132 }
133 }
134 }
135 }
136
145 inline int new_kind(int num_items,
146 int num_bytes,
147 AttributeMap *att = nullptr) {
148
149 if (num_items < 1 || num_items > MAX_ITEMS_IN_KIND)
150 return SERVICE_ERROR_WRONG_ARGUMENTS;
151
152 int rq_sz = sizeof(BlockHeader) + sizeof(StringBuffer) + num_items*sizeof(ItemHeader) + 2*num_items;
153
154 if (att != nullptr)
155 rq_sz += 2*att->size();
156
157 if (num_bytes < rq_sz)
158 return SERVICE_ERROR_NO_MEM;
159
160 memset(&cell_type, 0, num_bytes);
161
162 cell_type = CELL_TYPE_KIND_ITEM;
163 rank = 1;
164 range.dim[0] = 1;
165 size = num_items;
166 total_bytes = num_bytes;
167
168 set_attributes(att);
169
170 return SERVICE_NO_ERROR;
171 }
172
191 inline bool add_item(int idx,
192 char const *p_name,
193 int *p_dim,
194 int cell_type,
195 AttributeMap *p_dims) {
196
197 if (idx < 0 || idx >= size)
198 return false;
199
200 ItemHeader *p_it_hea = &tensor.cell_item[idx];
201
202 int rank = 6, j, k;
203
205
206 for (int i = MAX_TENSOR_RANK - 1; i >= 0; i--) {
207 j = p_dim[i];
208 p_it_hea->dim[i] = j;
209 if (j == 0) {
210 rank = i;
211
212 if (!i)
213 return false;
214
215 } else if (j < 0) {
216 if (p_dims == nullptr)
217 return false;
218
219 AttributeMap::iterator it = p_dims->find(j);
220 if (it == p_dims->end())
221 return false;
222
223 k = get_string_offset(psb, it->second);
224
225 if (k <= STRING_EMPTY)
226 return false;
227
228 p_it_hea->dim[i] = -k;
229 }
230 }
231
232 p_it_hea->name = get_string_offset(psb, p_name);
233
234 if (p_it_hea->name <= STRING_EMPTY)
235 return false;
236
237 p_it_hea->cell_type = cell_type;
238 p_it_hea->rank = rank;
239
240 return true;
241 }
242
243 int audit();
244};
245typedef Kind *pKind;
246
247} // namespace jazz_elements
248
249#endif // ifndef INCLUDED_JAZZ_ELEMENTS_KIND
A block is a moveable BlockHeader followed by a Tensor and a StringBuffer.
Definition block.h:99
int get_string_offset(pStringBuffer psb, const char *p_str)
Definition block.cpp:128
pStringBuffer p_string_buffer()
Definition block.h:363
void set_attributes(AttributeMap *all_att)
Definition block.h:268
Kind: A type definition for Jazz Blocks and Tuples.
Definition kind.h:83
int audit()
Audit a Kind.
Definition kind.cpp:47
bool add_item(int idx, char const *p_name, int *p_dim, int cell_type, AttributeMap *p_dims)
Definition kind.h:191
int new_kind(int num_items, int num_bytes, AttributeMap *att=nullptr)
Definition kind.h:145
char * item_name(int idx)
Definition kind.h:95
void dimensions(Dimensions &dims)
Definition kind.h:121
int index(pChar name)
Definition kind.h:108
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
std::set< std::string > Dimensions
An set::set with the dimension names returned by kind.dimensions()
Definition types.h:235
Kind * pKind
A pointer to a Kind object.
Definition kind.h:245
char * pChar
A pointer to a char buffer.
Definition types.h:185
std::map< int, const char * > AttributeMap
An stdlib map to store all the attributes of a Block at the same time used by the some Block methods.
Definition block.h:63
Header for a Movable Block (Tensor, Kind or Tuple) or a Dynamic Block (Index)
Definition types.h:242
Header for an item (of a Kind or Tuple)
Definition types.h:198
int name
The name of this item as an offset in StringBuffer.
Definition types.h:200
int dim[MAX_TENSOR_RANK]
Dimensions for the Tensor. For Kind: negative numbers are dimension names as -offset in StringBuffer.
Definition types.h:202
int rank
The number of dimensions.
Definition types.h:201
int cell_type
The type for the cells in the item. See CELL_TYPE_*.
Definition types.h:199
int size
The total number of cells in the tensor.
Definition types.h:267
int cell_type
The type for the cells in the tensor. See CELL_TYPE_*.
Definition types.h:266
Tensor tensor
A tensor for type cell_type and dimensions set by Block.set_dimensions()
Definition types.h:276
int total_bytes
Total size of the block everything included.
Definition types.h:272
int rank
The number of dimensions.
Definition types.h:269
TensorDim range
The dimensions of the tensor in terms of ranges (Max. size is 2 Gb.)
Definition types.h:270
Structure at the end of a Block, initially created with init_string_buffer()
Definition types.h:282
char buffer[]
The buffer where strings are stored starting with two zeroes for STRING_NA & STRING_EMPTY.
Definition types.h:287
int dim[MAX_TENSOR_RANK]
Dimensions for the Tensor. The product of all * (cell_type & 0xff) < 2 Gb.
Definition types.h:193
ItemHeader cell_item[0]
.. An array of BlockHeader used by Kinds and Tuples
Definition types.h:231