fastconstmap 0.7.0__tar.gz → 0.8.0__tar.gz
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.
- {fastconstmap-0.7.0/fastconstmap.egg-info → fastconstmap-0.8.0}/PKG-INFO +1 -1
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/fastconstmap/__init__.py +1 -1
- {fastconstmap-0.7.0 → fastconstmap-0.8.0/fastconstmap.egg-info}/PKG-INFO +1 -1
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/pyproject.toml +1 -1
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/src/constmap.c +10 -2
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/src/constmap.h +2 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/src/fastconstmap_module.c +2 -5
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/tests/test_constmap.py +26 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/LICENSE +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/MANIFEST.in +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/README.md +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/benchmarks/benchmark.py +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/examples/example.py +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/fastconstmap/_fastconstmap.pyi +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/fastconstmap/py.typed +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/fastconstmap.egg-info/SOURCES.txt +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/fastconstmap.egg-info/dependency_links.txt +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/fastconstmap.egg-info/top_level.txt +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/setup.cfg +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/setup.py +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/src/third_party/xxhash/LICENSE +0 -0
- {fastconstmap-0.7.0 → fastconstmap-0.8.0}/src/third_party/xxhash/xxhash.h +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "fastconstmap"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.8.0"
|
|
8
8
|
description = "Fast, immutable, compact map from strings to uint64 (binary fuse filter)."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "Apache-2.0" }
|
|
@@ -416,6 +416,7 @@ int fcm_constmap_new(fcm_constmap_t *out,
|
|
|
416
416
|
out->segment_count = params.segment_count;
|
|
417
417
|
out->segment_count_length = params.segment_count_length;
|
|
418
418
|
out->data_len = params.array_len;
|
|
419
|
+
out->n = size;
|
|
419
420
|
out->data = data;
|
|
420
421
|
data = NULL; /* ownership transferred */
|
|
421
422
|
|
|
@@ -497,6 +498,7 @@ int fcm_verified_constmap_new(fcm_verified_constmap_t *out,
|
|
|
497
498
|
out->segment_count = params.segment_count;
|
|
498
499
|
out->segment_count_length = params.segment_count_length;
|
|
499
500
|
out->data_len = params.array_len;
|
|
501
|
+
out->n = size;
|
|
500
502
|
out->data = data;
|
|
501
503
|
out->checks = checks;
|
|
502
504
|
data = NULL;
|
|
@@ -631,7 +633,7 @@ int fcm_constmap_write(const fcm_constmap_t *cm, void *buf) {
|
|
|
631
633
|
fcm_write_u32(p, cm->segment_length); p += 4;
|
|
632
634
|
fcm_write_u32(p, cm->segment_count); p += 4;
|
|
633
635
|
fcm_write_u32(p, cm->data_len); p += 4;
|
|
634
|
-
fcm_write_u32(p,
|
|
636
|
+
fcm_write_u32(p, cm->n); p += 4; /* original key count (was reserved) */
|
|
635
637
|
for (uint32_t i = 0; i < cm->data_len; i++) {
|
|
636
638
|
fcm_write_u64(p, cm->data[i]); p += 8;
|
|
637
639
|
}
|
|
@@ -652,6 +654,7 @@ int fcm_constmap_read(fcm_constmap_t *out, const void *buf, size_t buf_len) {
|
|
|
652
654
|
uint32_t segment_length = fcm_read_u32(p + 16);
|
|
653
655
|
uint32_t segment_count = fcm_read_u32(p + 20);
|
|
654
656
|
uint32_t data_len = fcm_read_u32(p + 24);
|
|
657
|
+
uint32_t n = fcm_read_u32(p + 28); /* original key count */
|
|
655
658
|
|
|
656
659
|
size_t expected = FCM_HEADER_SIZE + (size_t)data_len * 8u + FCM_TRAILER_SIZE;
|
|
657
660
|
if (buf_len < expected) return FCM_E_SHORT_BUFFER;
|
|
@@ -675,6 +678,7 @@ int fcm_constmap_read(fcm_constmap_t *out, const void *buf, size_t buf_len) {
|
|
|
675
678
|
out->segment_count = segment_count;
|
|
676
679
|
out->segment_count_length = segment_count * segment_length;
|
|
677
680
|
out->data_len = data_len;
|
|
681
|
+
out->n = n;
|
|
678
682
|
out->data = data;
|
|
679
683
|
return FCM_OK;
|
|
680
684
|
}
|
|
@@ -691,7 +695,7 @@ int fcm_verified_constmap_write(const fcm_verified_constmap_t *vm, void *buf) {
|
|
|
691
695
|
fcm_write_u32(p, vm->segment_length); p += 4;
|
|
692
696
|
fcm_write_u32(p, vm->segment_count); p += 4;
|
|
693
697
|
fcm_write_u32(p, vm->data_len); p += 4;
|
|
694
|
-
fcm_write_u32(p,
|
|
698
|
+
fcm_write_u32(p, vm->n); p += 4; /* original key count (was reserved) */
|
|
695
699
|
for (uint32_t i = 0; i < vm->data_len; i++) {
|
|
696
700
|
fcm_write_u64(p, vm->data[i]); p += 8;
|
|
697
701
|
}
|
|
@@ -715,6 +719,7 @@ int fcm_verified_constmap_read(fcm_verified_constmap_t *out, const void *buf, si
|
|
|
715
719
|
uint32_t segment_length = fcm_read_u32(p + 16);
|
|
716
720
|
uint32_t segment_count = fcm_read_u32(p + 20);
|
|
717
721
|
uint32_t data_len = fcm_read_u32(p + 24);
|
|
722
|
+
uint32_t n = fcm_read_u32(p + 28); /* original key count */
|
|
718
723
|
|
|
719
724
|
size_t expected = FCM_HEADER_SIZE + (size_t)data_len * 16u + FCM_TRAILER_SIZE;
|
|
720
725
|
if (buf_len < expected) return FCM_E_SHORT_BUFFER;
|
|
@@ -744,6 +749,7 @@ int fcm_verified_constmap_read(fcm_verified_constmap_t *out, const void *buf, si
|
|
|
744
749
|
out->segment_count = segment_count;
|
|
745
750
|
out->segment_count_length = segment_count * segment_length;
|
|
746
751
|
out->data_len = data_len;
|
|
752
|
+
out->n = n;
|
|
747
753
|
out->data = data;
|
|
748
754
|
out->checks = checks;
|
|
749
755
|
return FCM_OK;
|
|
@@ -785,6 +791,7 @@ int fcm_constmap_view(fcm_constmap_t *out, const void *buf, size_t buf_len) {
|
|
|
785
791
|
out->segment_count = fcm_read_u32(p + 20);
|
|
786
792
|
out->segment_count_length = out->segment_count * segment_length;
|
|
787
793
|
out->data_len = data_len;
|
|
794
|
+
out->n = fcm_read_u32(p + 28); /* original key count */
|
|
788
795
|
/* Borrowed pointer into `buf`; the integer round-trip launders away the
|
|
789
796
|
* source const-ness. Lookups only read this array. */
|
|
790
797
|
out->data = (uint64_t *)(uintptr_t)dp;
|
|
@@ -819,6 +826,7 @@ int fcm_verified_constmap_view(fcm_verified_constmap_t *out, const void *buf, si
|
|
|
819
826
|
out->segment_count = fcm_read_u32(p + 20);
|
|
820
827
|
out->segment_count_length = out->segment_count * segment_length;
|
|
821
828
|
out->data_len = data_len;
|
|
829
|
+
out->n = fcm_read_u32(p + 28); /* original key count */
|
|
822
830
|
out->data = (uint64_t *)(uintptr_t)dp;
|
|
823
831
|
out->checks = (uint64_t *)(uintptr_t)cp;
|
|
824
832
|
return FCM_OK;
|
|
@@ -36,6 +36,7 @@ typedef struct fcm_constmap {
|
|
|
36
36
|
uint32_t segment_count;
|
|
37
37
|
uint32_t segment_count_length;
|
|
38
38
|
uint32_t data_len;
|
|
39
|
+
uint32_t n; /* original number of inserted keys */
|
|
39
40
|
uint64_t *data;
|
|
40
41
|
} fcm_constmap_t;
|
|
41
42
|
|
|
@@ -46,6 +47,7 @@ typedef struct fcm_verified_constmap {
|
|
|
46
47
|
uint32_t segment_count;
|
|
47
48
|
uint32_t segment_count_length;
|
|
48
49
|
uint32_t data_len;
|
|
50
|
+
uint32_t n; /* original number of inserted keys */
|
|
49
51
|
uint64_t *data;
|
|
50
52
|
uint64_t *checks;
|
|
51
53
|
} fcm_verified_constmap_t;
|
|
@@ -290,10 +290,7 @@ fail:
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
static Py_ssize_t PyConstMap_length(PyConstMap *self) {
|
|
293
|
-
|
|
294
|
-
* The Python wrapper stores it separately if needed; here we report 0
|
|
295
|
-
* since we don't track it (Map is anonymous). */
|
|
296
|
-
return (Py_ssize_t)self->cm.data_len;
|
|
293
|
+
return (Py_ssize_t)self->cm.n;
|
|
297
294
|
}
|
|
298
295
|
|
|
299
296
|
static PyObject *PyConstMap_subscript(PyConstMap *self, PyObject *key) {
|
|
@@ -661,7 +658,7 @@ fail:
|
|
|
661
658
|
}
|
|
662
659
|
|
|
663
660
|
static Py_ssize_t PyVerifiedConstMap_length(PyVerifiedConstMap *self) {
|
|
664
|
-
return (Py_ssize_t)self->vm.
|
|
661
|
+
return (Py_ssize_t)self->vm.n;
|
|
665
662
|
}
|
|
666
663
|
|
|
667
664
|
static PyObject *PyVerifiedConstMap_serialize(PyVerifiedConstMap *self, PyObject *Py_UNUSED(ignored)) {
|
|
@@ -23,6 +23,19 @@ def test_empty():
|
|
|
23
23
|
assert len(m) == 0
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
def test_len():
|
|
27
|
+
d = {"apple": 100, "banana": 200, "cherry": 300}
|
|
28
|
+
m = ConstMap(d)
|
|
29
|
+
assert len(m) == 3
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_len_after_serialization():
|
|
33
|
+
d = {"a": 1, "b": 2, "c": 3, "d": 4}
|
|
34
|
+
m = ConstMap(d)
|
|
35
|
+
m2 = ConstMap.from_bytes(m.to_bytes())
|
|
36
|
+
assert len(m2) == 4
|
|
37
|
+
|
|
38
|
+
|
|
26
39
|
def test_single_key():
|
|
27
40
|
m = ConstMap({"only": 42})
|
|
28
41
|
assert m["only"] == 42
|
|
@@ -148,6 +161,19 @@ def test_verified_basic():
|
|
|
148
161
|
assert vm[k] == v
|
|
149
162
|
|
|
150
163
|
|
|
164
|
+
def test_verified_len():
|
|
165
|
+
d = {"apple": 100, "banana": 200, "cherry": 300}
|
|
166
|
+
vm = VerifiedConstMap(d)
|
|
167
|
+
assert len(vm) == 3
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_verified_len_after_serialization():
|
|
171
|
+
d = {"a": 1, "b": 2, "c": 3, "d": 4}
|
|
172
|
+
vm = VerifiedConstMap(d)
|
|
173
|
+
vm2 = VerifiedConstMap.from_bytes(vm.to_bytes())
|
|
174
|
+
assert len(vm2) == 4
|
|
175
|
+
|
|
176
|
+
|
|
151
177
|
def test_verified_missing_raises():
|
|
152
178
|
vm = VerifiedConstMap({"a": 1, "b": 2})
|
|
153
179
|
with pytest.raises(KeyError):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|