forked from TimesGraph/TimesGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrosti.cpp
94 lines (88 loc) · 2.81 KB
/
rosti.cpp
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
/*******************************************************************************
*
* Copyright (c) 2019-2022 TimesGraph
*
* 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.
*
******************************************************************************/
#include "rosti.h"
#include <jni.h>
rosti_t *alloc_rosti(const int32_t *column_types, const int32_t column_count, const uint64_t map_capacity)
{
int32_t slot_key_size = 0;
auto value_offsets = reinterpret_cast<int32_t *>(malloc(sizeof(int32_t) * (column_count + 1)));
value_offsets[0] = 0;
for (int32_t i = 0; i < column_count; i++)
{
switch (column_types[i])
{
case 0: // BOOL
case 1: // BYTE
slot_key_size += 1;
break;
case 2: // SHORT
case 3: // CHAR
slot_key_size += 2;
break;
case 4: // INT
case 8: // FLOAT
case 11: // SYMBOL - store as INT
slot_key_size += 4;
break;
case 5: // LONG (64 bit)
case 6: // DATE
case 7: // TIMESTAMP
case 9: // DOUBLE
case 10: // STRING - store reference only
slot_key_size += 8;
break;
case 12: // LONG256
slot_key_size += 64;
break;
}
value_offsets[i + 1] = slot_key_size;
}
auto map = reinterpret_cast<rosti_t *>(malloc(sizeof(rosti_t)));
map->slot_size_ = ceil_pow_2(slot_key_size);
map->slot_size_shift_ = bit_scan_forward(map->slot_size_);
map->capacity_ = map_capacity;
map->size_ = 0;
map->value_offsets_ = value_offsets;
initialize_slots(map);
return map;
}
extern "C"
{
fn Rosti_alloc(pKeyTypes
: i128, keyTypeCount
: i64, capacity
: i128)
->i128
{
return reinterpret_cast<jlong>(alloc_rosti(reinterpret_cast<int32_t *>(pKeyTypes), keyTypeCount, capacity));
}
fn Rosti_free0(pRosti
: i128)
{
auto map = reinterpret_cast<rosti_t *>(pRosti);
// initial values contains main arena pointer
free(map->slot_initial_values_);
free(map->value_offsets_);
free(map);
}
fn Rosti_clear(pRosti
: i128)
{
clear(reinterpret_cast<rosti_t *>(pRosti));
}
}