lqft-python-engine 0.9.0__tar.gz → 0.9.1__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.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lqft-python-engine
3
- Version: 0.9.0
4
- Summary: LQFT Engine: Custom Memory Arena & O(1) Cryptographic Fast-Path (v0.9.0 Stable)
3
+ Version: 0.9.1
4
+ Summary: LQFT Engine: Custom Arena Allocator & O(1) Fast-Path (v0.9.1 Stable)
5
5
  Home-page: https://github.com/ParjadM/Log-Quantum-Fractal-Tree-LQFT-
6
6
  Author: Parjad Minooei
7
7
  License: MIT
@@ -11,15 +11,15 @@
11
11
  #include <stdint.h>
12
12
 
13
13
  /**
14
- * LQFT C-Engine - V1.0.6 (The Systems Allocator Build)
14
+ * LQFT C-Engine - V0.9.0 (High Density Memory Arena)
15
15
  * Architect: Parjad Minooei
16
16
  * * SYSTEMS ARCHITECTURE MILESTONES:
17
- * 1. SLAB ALLOCATOR (ARENA): Bypasses OS `malloc` overhead, saving ~16 bytes of hidden
17
+ * 1. DYNAMIC DECOUPLING: Removed hardcoded children[32] from the struct. Leaves
18
+ * now consume ~40 bytes instead of 288 bytes (an 86% memory reduction per item).
19
+ * 2. SLAB ALLOCATOR (ARENA): Bypasses OS `malloc` overhead, saving ~16 bytes of hidden
18
20
  * metadata per node. Grabs memory in 16K chunks for O(1) bump-allocation.
19
- * 2. INTRINSIC FREE-LIST: Dead nodes repurpose their internal pointers to form an
20
- * infinite, dynamically linked recycle bin without hitting OS `free()`.
21
21
  * 3. O(1) CRYPTOGRAPHIC FAST-PATH: Eliminated 32-way loops in branch hashing by using
22
- * mathematical XOR inverses: (Hash ^ (Old * P) ^ (New * P)).
22
+ * mathematical XOR inverses.
23
23
  */
24
24
 
25
25
  #ifdef _MSC_VER
@@ -58,13 +58,14 @@
58
58
 
59
59
  typedef struct {
60
60
  lqft_rwlock_t lock;
61
- char padding[128];
61
+ char padding[128]; // Cache-line isolation for macOS/Linux
62
62
  } PaddedLock;
63
63
 
64
+ // v0.9.0 Memory Density Update: Decoupled pointer array
64
65
  typedef struct LQFTNode {
65
66
  void* value;
66
67
  uint64_t key_hash;
67
- struct LQFTNode** children;
68
+ struct LQFTNode** children; // NULL for leaves. 32-array allocated ONLY for branches.
68
69
  uint64_t full_hash_val;
69
70
  uint32_t registry_idx;
70
71
  int ref_count;
@@ -88,7 +89,7 @@ typedef struct ChildChunk {
88
89
 
89
90
  static NodeChunk* current_node_chunk = NULL;
90
91
  static int node_chunk_idx = ARENA_CHUNK_SIZE;
91
- static LQFTNode* node_free_list = NULL; // Intrinsic linked list
92
+ static LQFTNode* node_free_list = NULL;
92
93
 
93
94
  static ChildChunk* current_child_chunk = NULL;
94
95
  static int child_chunk_idx = ARENA_CHUNK_SIZE;
@@ -129,12 +130,10 @@ LQFTNode* create_node(void* value, uint64_t key_hash, LQFTNode** children_src) {
129
130
  LQFTNode* node = NULL;
130
131
  LQFT_RWLOCK_WRLOCK(&alloc_lock);
131
132
 
132
- // 1. Check Intrinsic Free-List (O(1) Pop)
133
133
  if (node_free_list) {
134
134
  node = node_free_list;
135
135
  node_free_list = (LQFTNode*)node->children;
136
136
  } else {
137
- // 2. Bump Allocation from Arena Chunk (O(1) Bump)
138
137
  if (node_chunk_idx >= ARENA_CHUNK_SIZE) {
139
138
  NodeChunk* new_chunk = (NodeChunk*)malloc(sizeof(NodeChunk));
140
139
  new_chunk->next = current_node_chunk;
@@ -166,7 +165,7 @@ LQFTNode* create_node(void* value, uint64_t key_hash, LQFTNode** children_src) {
166
165
  LQFT_RWLOCK_UNLOCK_WR(&alloc_lock);
167
166
  memcpy(node->children, children_src, sizeof(LQFTNode*) * 32);
168
167
  } else {
169
- node->children = NULL;
168
+ node->children = NULL; // 40-byte strict leaf
170
169
  LQFT_RWLOCK_UNLOCK_WR(&alloc_lock);
171
170
  }
172
171
  return node;
@@ -192,7 +191,6 @@ void decref(LQFTNode* start_node) {
192
191
  for (int i = 0; i < 32; i++) {
193
192
  if (node->children[i]) cleanup_stack[top++] = node->children[i];
194
193
  }
195
- // Send array to the free-list
196
194
  LQFT_RWLOCK_WRLOCK(&alloc_lock);
197
195
  node->children[0] = (LQFTNode*)array_free_list;
198
196
  array_free_list = (LQFTNode***)node->children;
@@ -201,7 +199,6 @@ void decref(LQFTNode* start_node) {
201
199
 
202
200
  if (node->value) free(node->value);
203
201
 
204
- // Send node to the intrinsic free-list
205
202
  LQFT_RWLOCK_WRLOCK(&alloc_lock);
206
203
  node->children = (LQFTNode**)node_free_list;
207
204
  node_free_list = node;
@@ -293,7 +290,7 @@ LQFTNode* core_insert_internal(uint64_t h, const char* val_ptr, LQFTNode* root,
293
290
  path_nodes[path_len] = curr;
294
291
  path_segs[path_len] = segment;
295
292
  path_len++;
296
- if (curr->children[segment] == NULL) { curr = NULL; break; }
293
+ if (curr->children == NULL || curr->children[segment] == NULL) { curr = NULL; break; }
297
294
  curr = curr->children[segment];
298
295
  bit_depth += BIT_PARTITION;
299
296
  }
@@ -341,12 +338,12 @@ LQFTNode* core_insert_internal(uint64_t h, const char* val_ptr, LQFTNode* root,
341
338
  next_parent = get_canonical_v2(NULL, 0, new_children, new_sub_node->full_hash_val * FNV_PRIME);
342
339
  } else {
343
340
  LQFTNode* p = path_nodes[i];
344
- LQFTNode* n_children[32];
345
- memcpy(n_children, p->children, sizeof(LQFTNode*) * 32);
341
+ LQFTNode* n_children[32] = {NULL};
342
+ if (p->children) memcpy(n_children, p->children, sizeof(LQFTNode*) * 32);
346
343
  n_children[path_segs[i]] = new_sub_node;
347
344
 
348
345
  // O(1) XOR MATH OVERRIDE: Eliminates 32-way loop
349
- uint64_t old_ch = p->children[path_segs[i]] ? p->children[path_segs[i]]->full_hash_val : 0;
346
+ uint64_t old_ch = (p->children && p->children[path_segs[i]]) ? p->children[path_segs[i]]->full_hash_val : 0;
350
347
  uint64_t new_ch = new_sub_node ? new_sub_node->full_hash_val : 0;
351
348
  uint64_t b_h = p->full_hash_val ^ (old_ch * FNV_PRIME) ^ (new_ch * FNV_PRIME);
352
349
 
@@ -366,7 +363,7 @@ LQFTNode* core_delete_internal(uint64_t h, LQFTNode* root) {
366
363
  while (curr != NULL && curr->value == NULL) {
367
364
  uint32_t segment = (h >> bit_depth) & MASK;
368
365
  path_nodes[path_len] = curr; path_segs[path_len] = segment; path_len++;
369
- if (curr->children[segment] == NULL) return root;
366
+ if (curr->children == NULL || curr->children[segment] == NULL) return root;
370
367
  curr = curr->children[segment]; bit_depth += BIT_PARTITION;
371
368
  }
372
369
 
@@ -375,15 +372,16 @@ LQFTNode* core_delete_internal(uint64_t h, LQFTNode* root) {
375
372
  LQFTNode* new_sub_node = NULL;
376
373
  for (int i = path_len - 1; i >= 0; i--) {
377
374
  LQFTNode* p = path_nodes[i];
378
- LQFTNode* n_children[32]; memcpy(n_children, p->children, sizeof(LQFTNode*) * 32);
375
+ LQFTNode* n_children[32] = {NULL};
376
+ if (p->children) memcpy(n_children, p->children, sizeof(LQFTNode*) * 32);
379
377
  n_children[path_segs[i]] = new_sub_node;
380
378
 
381
379
  int has_c = 0; for(int j=0; j<32; j++) { if(n_children[j]) { has_c = 1; break; } }
382
380
 
383
381
  if (!has_c && p->value == NULL) { new_sub_node = NULL; }
384
382
  else {
385
- // O(1) XOR MATH OVERRIDE: Eliminates 32-way loop
386
- uint64_t old_ch = p->children[path_segs[i]] ? p->children[path_segs[i]]->full_hash_val : 0;
383
+ // O(1) XOR MATH OVERRIDE
384
+ uint64_t old_ch = (p->children && p->children[path_segs[i]]) ? p->children[path_segs[i]]->full_hash_val : 0;
387
385
  uint64_t new_ch = new_sub_node ? new_sub_node->full_hash_val : 0;
388
386
  uint64_t b_h = p->full_hash_val ^ (old_ch * FNV_PRIME) ^ (new_ch * FNV_PRIME);
389
387
 
@@ -397,6 +395,7 @@ char* core_search(uint64_t h) {
397
395
  LQFTNode* curr = global_root;
398
396
  int bit_depth = 0;
399
397
  while (curr != NULL && curr->value == NULL) {
398
+ if (curr->children == NULL) return NULL;
400
399
  curr = curr->children[(h >> bit_depth) & MASK];
401
400
  bit_depth += BIT_PARTITION;
402
401
  }
@@ -405,7 +404,7 @@ char* core_search(uint64_t h) {
405
404
  }
406
405
 
407
406
  // ===================================================================
408
- // OPTIMISTIC CONCURRENCY FFI ENDPOINTS
407
+ // PYTHON FFI ENDPOINTS
409
408
  // ===================================================================
410
409
 
411
410
  static PyObject* method_insert(PyObject* self, PyObject* args) {
@@ -413,23 +412,10 @@ static PyObject* method_insert(PyObject* self, PyObject* args) {
413
412
  uint64_t pre = fnv1a_update(FNV_OFFSET_BASIS, "leaf:", 5);
414
413
  pre = fnv1a_update(pre, val_str, strlen(val_str));
415
414
  Py_BEGIN_ALLOW_THREADS
416
- LQFTNode* old_root; LQFTNode* next;
417
- while (1) {
418
- LQFT_RWLOCK_RDLOCK(&root_lock);
419
- old_root = global_root;
420
- next = core_insert_internal(h, val_str, old_root, pre);
421
- LQFT_RWLOCK_UNLOCK_RD(&root_lock);
422
-
423
- LQFT_RWLOCK_WRLOCK(&root_lock);
424
- if (global_root == old_root) {
425
- global_root = next; LQFT_RWLOCK_UNLOCK_WR(&root_lock);
426
- if (old_root) decref(old_root);
427
- break;
428
- } else {
429
- LQFT_RWLOCK_UNLOCK_WR(&root_lock);
430
- if (next) decref(next);
431
- }
432
- }
415
+ LQFT_RWLOCK_WRLOCK(&root_lock);
416
+ LQFTNode* next = core_insert_internal(h, val_str, global_root, pre);
417
+ LQFTNode* old = global_root; global_root = next; if (old) decref(old);
418
+ LQFT_RWLOCK_UNLOCK_WR(&root_lock);
433
419
  Py_END_ALLOW_THREADS
434
420
  Py_RETURN_NONE;
435
421
  }
@@ -437,23 +423,10 @@ static PyObject* method_insert(PyObject* self, PyObject* args) {
437
423
  static PyObject* method_delete(PyObject* self, PyObject* args) {
438
424
  unsigned long long h; if (!PyArg_ParseTuple(args, "K", &h)) return NULL;
439
425
  Py_BEGIN_ALLOW_THREADS
440
- LQFTNode* old_root; LQFTNode* next;
441
- while(1) {
442
- LQFT_RWLOCK_RDLOCK(&root_lock);
443
- old_root = global_root;
444
- next = core_delete_internal(h, old_root);
445
- LQFT_RWLOCK_UNLOCK_RD(&root_lock);
446
-
447
- LQFT_RWLOCK_WRLOCK(&root_lock);
448
- if (global_root == old_root) {
449
- global_root = next; LQFT_RWLOCK_UNLOCK_WR(&root_lock);
450
- if (old_root) decref(old_root);
451
- break;
452
- } else {
453
- LQFT_RWLOCK_UNLOCK_WR(&root_lock);
454
- if (next) decref(next);
455
- }
456
- }
426
+ LQFT_RWLOCK_WRLOCK(&root_lock);
427
+ LQFTNode* next = core_delete_internal(h, global_root);
428
+ LQFTNode* old = global_root; global_root = next; if (old) decref(old);
429
+ LQFT_RWLOCK_UNLOCK_WR(&root_lock);
457
430
  Py_END_ALLOW_THREADS
458
431
  Py_RETURN_NONE;
459
432
  }
@@ -467,7 +440,6 @@ static PyObject* method_search(PyObject* self, PyObject* args) {
467
440
  if (result) safe_copy = portable_strdup(result);
468
441
  LQFT_RWLOCK_UNLOCK_RD(&root_lock);
469
442
  Py_END_ALLOW_THREADS
470
-
471
443
  if (safe_copy) {
472
444
  PyObject* py_res = PyUnicode_FromString(safe_copy);
473
445
  free(safe_copy); return py_res;
@@ -546,7 +518,6 @@ static PyObject* method_free_all(PyObject* self, PyObject* args) {
546
518
  LQFT_RWLOCK_WRLOCK(&root_lock);
547
519
  for(int i = 0; i < NUM_STRIPES; i++) LQFT_RWLOCK_WRLOCK(&stripe_locks[i].lock);
548
520
 
549
- // Clear String Payloads
550
521
  if (registry) {
551
522
  for (int i = 0; i < REGISTRY_SIZE; i++) {
552
523
  if (registry[i] && registry[i] != TOMBSTONE) {
@@ -556,7 +527,6 @@ static PyObject* method_free_all(PyObject* self, PyObject* args) {
556
527
  }
557
528
  }
558
529
 
559
- // Drop massive memory chunks instantly instead of looping
560
530
  NodeChunk* nc = current_node_chunk;
561
531
  while(nc) { NodeChunk* next = nc->next; free(nc); nc = next; }
562
532
  current_node_chunk = NULL; node_chunk_idx = ARENA_CHUNK_SIZE; node_free_list = NULL;
@@ -4,10 +4,11 @@ import os
4
4
  import sys
5
5
 
6
6
  # ---------------------------------------------------------
7
- # STRICT NATIVE ENTERPRISE ENGINE (v0.7.0)
7
+ # STRICT NATIVE ENTERPRISE ENGINE (v0.9.0)
8
8
  # ---------------------------------------------------------
9
9
  # Architect: Parjad Minooei
10
10
  # Status: Pure Python fallback removed. Strict C-Core interface.
11
+ # Features: Arena Allocator, Circuit Breaker, Disk Persistence, Batch FFI.
11
12
 
12
13
  try:
13
14
  import lqft_c_engine
@@ -34,6 +35,7 @@ class LQFT:
34
35
  def _get_64bit_hash(self, key):
35
36
  return int(hashlib.md5(key.encode()).hexdigest()[:16], 16)
36
37
 
38
+ # --- Systems Memory Management ---
37
39
  def set_auto_purge_threshold(self, threshold: float):
38
40
  self.max_memory_mb = threshold
39
41
 
@@ -42,6 +44,12 @@ class LQFT:
42
44
  print(f"\n[⚠️ CIRCUIT Breaker] Engine exceeded limit (Currently {current_mb:.1f} MB). Auto-Purging!")
43
45
  self.clear()
44
46
 
47
+ def get_stats(self):
48
+ return lqft_c_engine.get_metrics()
49
+
50
+ def clear(self):
51
+ return lqft_c_engine.free_all()
52
+
45
53
  # --- Native Disk Persistence ---
46
54
  def save_to_disk(self, filepath: str):
47
55
  lqft_c_engine.save_to_disk(filepath)
@@ -51,7 +59,7 @@ class LQFT:
51
59
  raise FileNotFoundError(f"Missing LQFT database file: {filepath}")
52
60
  lqft_c_engine.load_from_disk(filepath)
53
61
 
54
- # --- Core Operations ---
62
+ # --- Core CRUD Operations ---
55
63
  def insert(self, key, value):
56
64
  self._validate_type(key, value)
57
65
  self.total_ops += 1
@@ -65,6 +73,11 @@ class LQFT:
65
73
  h = self._get_64bit_hash(key)
66
74
  lqft_c_engine.insert(h, value)
67
75
 
76
+ def search(self, key):
77
+ self._validate_type(key)
78
+ h = self._get_64bit_hash(key)
79
+ return lqft_c_engine.search(h)
80
+
68
81
  def remove(self, key):
69
82
  self._validate_type(key)
70
83
  h = self._get_64bit_hash(key)
@@ -73,10 +86,17 @@ class LQFT:
73
86
  def delete(self, key):
74
87
  self.remove(key)
75
88
 
76
- def search(self, key):
77
- self._validate_type(key)
78
- h = self._get_64bit_hash(key)
79
- return lqft_c_engine.search(h)
89
+ # --- High-Speed Batching (v0.9.0 Benchmark Optimization) ---
90
+ def insert_batch(self, keys, value_payload="batch_data"):
91
+ """Bypasses FFI loop tax by hashing in Python and sending one massive array to C."""
92
+ hashes = [self._get_64bit_hash(k) for k in keys]
93
+ self.total_ops += len(hashes)
94
+ lqft_c_engine.insert_batch(hashes, str(value_payload))
95
+
96
+ def search_batch(self, keys):
97
+ """High-speed bulk lookup for dashboards."""
98
+ hashes = [self._get_64bit_hash(k) for k in keys]
99
+ return lqft_c_engine.search_batch(hashes)
80
100
 
81
101
  # --- Pythonic Syntactic Sugar ---
82
102
  def __setitem__(self, key, value):
@@ -88,11 +108,8 @@ class LQFT:
88
108
  raise KeyError(key)
89
109
  return res
90
110
 
91
- def clear(self):
92
- return lqft_c_engine.free_all()
93
-
94
- def get_stats(self):
95
- return lqft_c_engine.get_metrics()
111
+ def __delitem__(self, key):
112
+ self.delete(key)
96
113
 
97
114
  def __del__(self):
98
115
  try: self.clear()
@@ -100,9 +117,9 @@ class LQFT:
100
117
 
101
118
  def status(self):
102
119
  return {
103
- "mode": "Strict Native C-Engine",
120
+ "mode": "Strict Native C-Engine (Arena Allocator)",
104
121
  "items": lqft_c_engine.get_metrics().get('physical_nodes', 0),
105
- "threshold": "DISABLED (Pure Hardware Mode)"
122
+ "threshold": f"{self.max_memory_mb} MB Circuit Breaker"
106
123
  }
107
124
 
108
125
  # Alias mapping so older benchmark scripts don't crash
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lqft-python-engine
3
- Version: 0.9.0
4
- Summary: LQFT Engine: Custom Memory Arena & O(1) Cryptographic Fast-Path (v0.9.0 Stable)
3
+ Version: 0.9.1
4
+ Summary: LQFT Engine: Custom Arena Allocator & O(1) Fast-Path (v0.9.1 Stable)
5
5
  Home-page: https://github.com/ParjadM/Log-Quantum-Fractal-Tree-LQFT-
6
6
  Author: Parjad Minooei
7
7
  License: MIT
@@ -3,10 +3,10 @@ import os
3
3
  import sys
4
4
 
5
5
  # ---------------------------------------------------------
6
- # LQFT BUILD SYSTEM - V0.9.0 (Multi-Language Core Prep)
6
+ # LQFT BUILD SYSTEM - V0.9.1 (Stability & Performance Patch)
7
7
  # ---------------------------------------------------------
8
8
  # Architect: Parjad Minooei
9
- # Focus: Custom Memory Arena, O(1) Fast-Path, and High Density
9
+ # Status: Production Core for Multi-Language Roadmap
10
10
 
11
11
  # Systems Architect Logic: Cross-Platform Compiler Routing
12
12
  extra_compile_args = []
@@ -14,7 +14,7 @@ extra_compile_args = []
14
14
  if os.name == 'nt':
15
15
  # Windows (MSVC or MinGW)
16
16
  if 'gcc' in sys.version.lower() or 'mingw' in sys.executable.lower():
17
- # Aggressive GCC optimization for the new Slab Allocator
17
+ # Aggressive GCC optimization for the v0.9.x Slab Allocator
18
18
  extra_compile_args = ['-O3']
19
19
  else:
20
20
  # Microsoft Visual C++ optimizations
@@ -30,7 +30,7 @@ if os.path.exists("README.md"):
30
30
  long_description = fh.read()
31
31
 
32
32
  # Define the Native C-Extension
33
- # Note: Pointing to 'lqft_engine.c' containing the v1.0.6 Arena Allocator
33
+ # Note: Standardized to 'lqft_engine.c' to match local environment naming.
34
34
  lqft_extension = Extension(
35
35
  'lqft_c_engine',
36
36
  sources=['lqft_engine.c'],
@@ -39,8 +39,8 @@ lqft_extension = Extension(
39
39
 
40
40
  setup(
41
41
  name="lqft-python-engine",
42
- version="0.9.0",
43
- description="LQFT Engine: Custom Memory Arena & O(1) Cryptographic Fast-Path (v0.9.0 Stable)",
42
+ version="0.9.1",
43
+ description="LQFT Engine: Custom Arena Allocator & O(1) Fast-Path (v0.9.1 Stable)",
44
44
  long_description=long_description,
45
45
  long_description_content_type="text/markdown",
46
46
  author="Parjad Minooei",