lqft-python-engine 0.1.8__tar.gz → 0.2.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.
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: lqft-python-engine
3
+ Version: 0.2.0
4
+ Summary: LQFT Engine: Full CRUD Support & Enterprise Scaling (v4.5 Stable)
5
+ Home-page: https://github.com/ParjadM/Log-Quantum-Fractal-Tree-LQFT-
6
+ Author: Parjad Minooei
7
+ License: MIT
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE.md
15
+ Requires-Dist: psutil
16
+ Dynamic: author
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: license-file
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ Log-Quantum Fractal Tree Engine
@@ -11,12 +11,12 @@
11
11
  #include <stdint.h>
12
12
 
13
13
  /**
14
- * LQFT C-Engine - V4.4 (Large Payload Support)
14
+ * LQFT C-Engine - V4.5 (Full CRUD & Large Payload)
15
15
  * Architect: Parjad Minooei
16
16
  * * CHANGE LOG:
17
- * - Removed fixed 8KB stack buffer in get_canonical.
18
- * - Implemented Incremental FNV-1a Hashing to support multi-MB payloads.
19
- * - Optimized string interning for high-concurrency memory safety.
17
+ * - Added 'delete' method with bottom-up path reconstruction.
18
+ * - Maintains Incremental FNV-1a Hashing for large payloads.
19
+ * - Fixed Stack-to-Heap collision for multi-MB data.
20
20
  */
21
21
 
22
22
  #define BIT_PARTITION 5
@@ -35,7 +35,6 @@ static LQFTNode** registry = NULL;
35
35
  static int physical_node_count = 0;
36
36
  static LQFTNode* global_root = NULL;
37
37
 
38
- // Incremental FNV-1a Constants
39
38
  const uint64_t FNV_OFFSET_BASIS = 14695981039346656037ULL;
40
39
  const uint64_t FNV_PRIME = 1099511628211ULL;
41
40
 
@@ -77,18 +76,13 @@ LQFTNode* create_node(void* value, uint64_t key_hash) {
77
76
  LQFTNode* get_canonical(void* value, uint64_t key_hash, LQFTNode** children) {
78
77
  if (!init_registry()) return NULL;
79
78
 
80
- // V4.4 REFACTOR: Incremental hashing instead of sprintf concatenation
81
- // This avoids the 8KB buffer overflow for large payloads.
82
79
  uint64_t full_hash = FNV_OFFSET_BASIS;
83
-
84
80
  if (value != NULL) {
85
- const char* prefix = "leaf:";
86
- full_hash = fnv1a_update(full_hash, prefix, 5);
81
+ full_hash = fnv1a_update(full_hash, "leaf:", 5);
87
82
  full_hash = fnv1a_update(full_hash, value, strlen((char*)value));
88
83
  full_hash = fnv1a_update(full_hash, &key_hash, sizeof(uint64_t));
89
84
  } else {
90
- const char* prefix = "branch:";
91
- full_hash = fnv1a_update(full_hash, prefix, 7);
85
+ full_hash = fnv1a_update(full_hash, "branch:", 7);
92
86
  if (children) {
93
87
  for (int i = 0; i < 32; i++) {
94
88
  if (children[i]) {
@@ -102,8 +96,8 @@ LQFTNode* get_canonical(void* value, uint64_t key_hash, LQFTNode** children) {
102
96
  char lookup_hash[17];
103
97
  sprintf(lookup_hash, "%016llx", (unsigned long long)full_hash);
104
98
  uint32_t idx = full_hash % REGISTRY_SIZE;
105
-
106
99
  uint32_t start_idx = idx;
100
+
107
101
  while (registry[idx] != NULL) {
108
102
  if (strcmp(registry[idx]->struct_hash, lookup_hash) == 0) {
109
103
  if (value) free(value);
@@ -124,6 +118,58 @@ LQFTNode* get_canonical(void* value, uint64_t key_hash, LQFTNode** children) {
124
118
  return new_node;
125
119
  }
126
120
 
121
+ static PyObject* method_delete(PyObject* self, PyObject* args) {
122
+ unsigned long long h;
123
+ if (!PyArg_ParseTuple(args, "K", &h)) return NULL;
124
+ if (!global_root) Py_RETURN_NONE;
125
+
126
+ LQFTNode* path_nodes[20];
127
+ uint32_t path_segs[20];
128
+ int path_len = 0;
129
+ LQFTNode* curr = global_root;
130
+ int bit_depth = 0;
131
+
132
+ // Trace path to target
133
+ while (curr != NULL && curr->value == NULL) {
134
+ uint32_t segment = (h >> bit_depth) & MASK;
135
+ path_nodes[path_len] = curr;
136
+ path_segs[path_len] = segment;
137
+ path_len++;
138
+ curr = curr->children[segment];
139
+ bit_depth += BIT_PARTITION;
140
+ }
141
+
142
+ // If not found, exit
143
+ if (curr == NULL || curr->key_hash != h) Py_RETURN_NONE;
144
+
145
+ // Rebuild bottom-up: start with NULL (the deleted leaf)
146
+ LQFTNode* new_sub_node = NULL;
147
+
148
+ for (int i = path_len - 1; i >= 0; i--) {
149
+ LQFTNode* p_node = path_nodes[i];
150
+ uint32_t segment = path_segs[i];
151
+ LQFTNode* new_children[32];
152
+ int has_other_children = 0;
153
+
154
+ for (int j = 0; j < 32; j++) {
155
+ if (j == segment) new_children[j] = new_sub_node;
156
+ else {
157
+ new_children[j] = p_node->children[j];
158
+ if (new_children[j]) has_other_children = 1;
159
+ }
160
+ }
161
+
162
+ if (!has_other_children && i > 0) {
163
+ new_sub_node = NULL; // Contract empty branch
164
+ } else {
165
+ new_sub_node = get_canonical(NULL, 0, new_children);
166
+ }
167
+ }
168
+
169
+ global_root = (new_sub_node) ? new_sub_node : get_canonical(NULL, 0, NULL);
170
+ Py_RETURN_NONE;
171
+ }
172
+
127
173
  static PyObject* method_free_all(PyObject* self, PyObject* args) {
128
174
  if (registry != NULL) {
129
175
  for (int i = 0; i < REGISTRY_SIZE; i++) {
@@ -145,47 +191,34 @@ static PyObject* method_insert(PyObject* self, PyObject* args) {
145
191
  unsigned long long h;
146
192
  char* val_str;
147
193
  if (!PyArg_ParseTuple(args, "Ks", &h, &val_str)) return NULL;
148
-
149
194
  if (!global_root) {
150
195
  if (!init_registry()) return PyErr_NoMemory();
151
196
  global_root = get_canonical(NULL, 0, NULL);
152
197
  }
153
-
154
- LQFTNode* path_nodes[MAX_BITS];
155
- uint32_t path_segs[MAX_BITS];
198
+ LQFTNode* path_nodes[20];
199
+ uint32_t path_segs[20];
156
200
  int path_len = 0;
157
-
158
201
  LQFTNode* curr = global_root;
159
202
  int bit_depth = 0;
160
-
161
203
  while (curr != NULL && curr->value == NULL) {
162
204
  uint32_t segment = (h >> bit_depth) & MASK;
163
205
  path_nodes[path_len] = curr;
164
206
  path_segs[path_len] = segment;
165
207
  path_len++;
166
-
167
- if (curr->children[segment] == NULL) {
168
- curr = NULL;
169
- break;
170
- }
208
+ if (curr->children[segment] == NULL) { curr = NULL; break; }
171
209
  curr = curr->children[segment];
172
210
  bit_depth += BIT_PARTITION;
173
211
  }
174
-
175
212
  LQFTNode* new_sub_node = NULL;
176
- if (curr == NULL) {
177
- new_sub_node = get_canonical(portable_strdup(val_str), h, NULL);
178
- } else if (curr->key_hash == h) {
179
- new_sub_node = get_canonical(portable_strdup(val_str), h, curr->children);
180
- } else {
213
+ if (curr == NULL) { new_sub_node = get_canonical(portable_strdup(val_str), h, NULL); }
214
+ else if (curr->key_hash == h) { new_sub_node = get_canonical(portable_strdup(val_str), h, curr->children); }
215
+ else {
181
216
  unsigned long long old_h = curr->key_hash;
182
217
  char* old_val = portable_strdup((char*)curr->value);
183
218
  int temp_depth = bit_depth;
184
-
185
- while (temp_depth < MAX_BITS) {
219
+ while (temp_depth < 64) {
186
220
  uint32_t s_old = (old_h >> temp_depth) & MASK;
187
221
  uint32_t s_new = (h >> temp_depth) & MASK;
188
-
189
222
  if (s_old != s_new) {
190
223
  LQFTNode* c_old = get_canonical(old_val, old_h, curr->children);
191
224
  LQFTNode* c_new = get_canonical(portable_strdup(val_str), h, NULL);
@@ -194,16 +227,10 @@ static PyObject* method_insert(PyObject* self, PyObject* args) {
194
227
  new_children[s_new] = c_new;
195
228
  new_sub_node = get_canonical(NULL, 0, new_children);
196
229
  break;
197
- } else {
198
- path_nodes[path_len] = NULL;
199
- path_segs[path_len] = s_old;
200
- path_len++;
201
- temp_depth += BIT_PARTITION;
202
- }
230
+ } else { path_nodes[path_len] = NULL; path_segs[path_len] = s_old; path_len++; temp_depth += BIT_PARTITION; }
203
231
  }
204
232
  if (new_sub_node == NULL) new_sub_node = get_canonical(portable_strdup(val_str), h, curr->children);
205
233
  }
206
-
207
234
  for (int i = path_len - 1; i >= 0; i--) {
208
235
  if (path_nodes[i] == NULL) {
209
236
  LQFTNode* new_children[32] = {NULL};
@@ -218,7 +245,6 @@ static PyObject* method_insert(PyObject* self, PyObject* args) {
218
245
  new_sub_node = get_canonical(p_node->value, p_node->key_hash, new_children);
219
246
  }
220
247
  }
221
-
222
248
  global_root = new_sub_node;
223
249
  Py_RETURN_NONE;
224
250
  }
@@ -227,7 +253,6 @@ static PyObject* method_search(PyObject* self, PyObject* args) {
227
253
  unsigned long long h;
228
254
  if (!PyArg_ParseTuple(args, "K", &h)) return NULL;
229
255
  if (!global_root) Py_RETURN_NONE;
230
-
231
256
  LQFTNode* curr = global_root;
232
257
  int bit_depth = 0;
233
258
  while (curr != NULL && curr->value == NULL) {
@@ -244,10 +269,11 @@ static PyObject* method_get_metrics(PyObject* self, PyObject* args) {
244
269
  }
245
270
 
246
271
  static PyMethodDef LQFTMethods[] = {
247
- {"insert", method_insert, METH_VARARGS, "Insert payload"},
248
- {"search", method_search, METH_VARARGS, "Search hash"},
249
- {"get_metrics", method_get_metrics, METH_VARARGS, "Get metrics"},
250
- {"free_all", method_free_all, METH_VARARGS, "Reclaim memory"},
272
+ {"insert", method_insert, METH_VARARGS, "Insert key-value"},
273
+ {"delete", method_delete, METH_VARARGS, "Delete key"},
274
+ {"search", method_search, METH_VARARGS, "Search key"},
275
+ {"get_metrics", method_get_metrics, METH_VARARGS, "Get engine stats"},
276
+ {"free_all", method_free_all, METH_VARARGS, "Total memory wipe"},
251
277
  {NULL, NULL, 0, NULL}
252
278
  };
253
279
 
@@ -2,7 +2,7 @@ import hashlib
2
2
  import weakref
3
3
 
4
4
  # ---------------------------------------------------------
5
- # LEGACY PURE PYTHON LQFT (For reference/fallback)
5
+ # LEGACY PURE PYTHON LQFT (For reference/fallback/benchmarks)
6
6
  # ---------------------------------------------------------
7
7
  class LQFTNode:
8
8
  __slots__ = ['children', 'value', 'key_hash', 'struct_hash', '__weakref__']
@@ -115,8 +115,8 @@ except ImportError:
115
115
  class AdaptiveLQFT:
116
116
  """
117
117
  A polymorphic, heuristic-driven data structure wrapper.
118
- - Scale < 50,000: Acts as an ultra-lightweight C-Hash (Python Dict).
119
- - Scale > 50,000: Automatically migrates to the Native C-Engine LQFT
118
+ - Scale < threshold: Acts as an ultra-lightweight C-Hash (Python Dict).
119
+ - Scale > threshold: Automatically migrates to the Native C-Engine LQFT
120
120
  for Merkle-DAG deduplication and folding.
121
121
  """
122
122
  def __init__(self, migration_threshold=50000):
@@ -140,7 +140,7 @@ class AdaptiveLQFT:
140
140
 
141
141
  for key, val in self._light_store.items():
142
142
  h = self._get_64bit_hash(key)
143
- lqft_c_engine.insert(h, val)
143
+ lqft_c_engine.insert(h, str(val))
144
144
 
145
145
  # Clear the lightweight store to free up memory
146
146
  self._light_store.clear()
@@ -159,7 +159,7 @@ class AdaptiveLQFT:
159
159
  else:
160
160
  # Phase 2: Massive Data Operations (Native C-Heap)
161
161
  h = self._get_64bit_hash(key)
162
- lqft_c_engine.insert(h, value)
162
+ lqft_c_engine.insert(h, str(value))
163
163
 
164
164
  def search(self, key):
165
165
  if not self.is_native:
@@ -168,9 +168,23 @@ class AdaptiveLQFT:
168
168
  h = self._get_64bit_hash(key)
169
169
  return lqft_c_engine.search(h)
170
170
 
171
+ def remove(self, key):
172
+ """Deletes a key from either the light store or the Merkle tree."""
173
+ if not self.is_native:
174
+ if key in self._light_store:
175
+ del self._light_store[key]
176
+ self.size -= 1
177
+ else:
178
+ h = self._get_64bit_hash(key)
179
+ lqft_c_engine.delete(h)
180
+
181
+ def delete(self, key):
182
+ """Alias for remove to satisfy all testing suites."""
183
+ self.remove(key)
184
+
171
185
  def clear(self):
172
186
  """
173
- Memory Reclamation: Manually trigger C-level heap cleanup.
187
+ Memory Reclamation: Manually trigger heap cleanup.
174
188
  In the Adaptive model, this handles both the Python dict and the C-Registry.
175
189
  """
176
190
  self._light_store.clear()
@@ -179,21 +193,23 @@ class AdaptiveLQFT:
179
193
  return lqft_c_engine.free_all()
180
194
  return 0
181
195
 
196
+ def get_stats(self):
197
+ """Fetches memory metrics from the C-Engine if active."""
198
+ if self.is_native and C_ENGINE_READY:
199
+ return lqft_c_engine.get_metrics()
200
+ return {"physical_nodes": 0}
201
+
182
202
  def __del__(self):
183
- """
184
- Finalizer: Reclaims unmanaged C memory when the Python object is deleted.
185
- Crucial for preventing memory leaks in long-running systems.
186
- """
203
+ """Finalizer: Reclaims unmanaged C memory when the Python object is deleted."""
187
204
  try:
188
205
  self.clear()
189
206
  except:
190
- # Silence errors during late interpreter shutdown/garbage collection
191
207
  pass
192
208
 
193
209
  def status(self):
194
210
  """Returns the current state of the engine."""
195
211
  return {
196
212
  "mode": "Native Merkle-DAG" if self.is_native else "Lightweight C-Hash",
197
- "items": self.size,
213
+ "items": self.size if not self.is_native else lqft_c_engine.get_metrics().get('physical_nodes', self.size),
198
214
  "threshold": self.threshold
199
215
  }
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: lqft-python-engine
3
+ Version: 0.2.0
4
+ Summary: LQFT Engine: Full CRUD Support & Enterprise Scaling (v4.5 Stable)
5
+ Home-page: https://github.com/ParjadM/Log-Quantum-Fractal-Tree-LQFT-
6
+ Author: Parjad Minooei
7
+ License: MIT
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE.md
15
+ Requires-Dist: psutil
16
+ Dynamic: author
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: license-file
23
+ Dynamic: requires-dist
24
+ Dynamic: requires-python
25
+ Dynamic: summary
26
+
27
+ Log-Quantum Fractal Tree Engine
@@ -15,10 +15,7 @@ else:
15
15
 
16
16
  # Load README for PyPI long_description
17
17
  long_description = "Log-Quantum Fractal Tree Engine"
18
- if os.path.exists("readme.md"):
19
- with open("readme.md", "r", encoding="utf-8") as fh:
20
- long_description = fh.read()
21
- elif os.path.exists("README.md"):
18
+ if os.path.exists("README.md"):
22
19
  with open("README.md", "r", encoding="utf-8") as fh:
23
20
  long_description = fh.read()
24
21
 
@@ -30,8 +27,8 @@ lqft_extension = Extension(
30
27
 
31
28
  setup(
32
29
  name="lqft-python-engine",
33
- version="0.1.8",
34
- description="LQFT Engine: High-Performance Deduplicating Data Structure (V4.4 Stable)",
30
+ version="0.2.0",
31
+ description="LQFT Engine: Full CRUD Support & Enterprise Scaling (v4.5 Stable)",
35
32
  long_description=long_description,
36
33
  long_description_content_type="text/markdown",
37
34
  author="Parjad Minooei",
@@ -1,96 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: lqft-python-engine
3
- Version: 0.1.8
4
- Summary: LQFT Engine: High-Performance Deduplicating Data Structure (V4.4 Stable)
5
- Home-page: https://github.com/ParjadM/Log-Quantum-Fractal-Tree-LQFT-
6
- Author: Parjad Minooei
7
- License: MIT
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.12
10
- Classifier: Operating System :: OS Independent
11
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
- Requires-Python: >=3.8
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE.md
15
- Requires-Dist: psutil
16
- Dynamic: author
17
- Dynamic: classifier
18
- Dynamic: description
19
- Dynamic: description-content-type
20
- Dynamic: home-page
21
- Dynamic: license
22
- Dynamic: license-file
23
- Dynamic: requires-dist
24
- Dynamic: requires-python
25
- Dynamic: summary
26
-
27
- # Log-Quantum Fractal Tree (LQFT) 🚀
28
-
29
- **Architect:** [Parjad Minooei](https://www.linkedin.com/in/parjadminooei)
30
- **Portfolio:** [parjadm.ca](https://www.parjadm.ca/)
31
-
32
- ---
33
-
34
- ## 📌 Executive Summary
35
-
36
- The **Log-Quantum Fractal Tree (LQFT)** is a high-performance, scale-invariant data structure engine designed for massive data deduplication and persistent state management. By bridging a **native C-Engine** with a **Python Foreign Function Interface (FFI)**, this project bypasses the Global Interpreter Lock (GIL) to achieve sub-microsecond search latencies and memory efficiency that scales with data entropy rather than data volume.
37
-
38
- ---
39
-
40
- ## 🧠 Formal Complexity Analysis
41
-
42
- As a Systems Architect, I have engineered the LQFT to move beyond the linear limitations of standard Python structures.
43
-
44
- ### 1. Time Complexity: $O(1)$ (Scale-Invariant)
45
- Unlike standard Trees ($O(\log N)$) or Lists ($O(N)$), the LQFT uses a fixed-depth 64-bit address space.
46
-
47
- * **Search/Insertion:** $O(1)$
48
- * **Mechanism:** The 64-bit hash is partitioned into 13 segments of 5-bits. This ensures that the path from the root to any leaf is physically capped at 13 hops, providing **deterministic latency** regardless of whether the database holds 1,000 or 1,000,000,000 items.
49
-
50
- ### 2. Space Complexity: $O(\Sigma)$ (Entropy-Based)
51
- Standard structures scale linearly based on the number of items ($N$). The LQFT scales based on the **Information Entropy** ($\Sigma$) of the dataset.
52
-
53
- * **Space:** $O(\Sigma)$
54
- * **Mechanism:** Utilizing **Merkle-DAG structural folding**, the engine detects identical data branches and reuses them in physical memory. In highly redundant datasets (e.g., DNA sequences or Log files), this results in sub-linear memory growth.
55
-
56
- ---
57
-
58
- ## 📊 Performance Benchmarks
59
- *Tested in Scarborough Lab: Python 3.12 | MinGW-w64 GCC-O3 Optimization*
60
-
61
- | Metric | Standard Python ($O(N)$) | LQFT C-Engine ($O(1)$) | Delta |
62
- | :--- | :--- | :--- | :--- |
63
- | **Search Latency (N=100k)** | ~3,564.84 μs | 0.50 μs | **7,129x Faster** |
64
- | **Insertion Time (N=100k)** | 41.05s | 1.07s | **38x Faster** |
65
- | **Memory (Versioning)** | $O(N \times V)$ | $O(\Sigma + V)$ | **99% Savings** |
66
-
67
- ---
68
-
69
- ## 🛠️ Architectural Pillars
70
-
71
- * **Native C-Engine Core:** Pushes memory allocation and bit-manipulation to the C-layer for hardware-level execution.
72
- * **Structural Folding:** A recursive structural hashing algorithm that collapses identical sub-trees into single pointers.
73
- * **Adaptive Migration:** A polymorphic wrapper (`AdaptiveLQFT`) that manages the transition from lightweight Python dictionaries to the heavy-duty C-Engine.
74
- * **Zero-Knowledge Integrity:** Fixed-depth pathing allows for 208-byte Merkle Proofs to verify data existence in microsecond time.
75
-
76
- ---
77
-
78
- ## ⚙️ Quick Start
79
-
80
- ### Compilation
81
- Ensure you have a C compiler (GCC/Clang) installed to build the FFI layer.
82
- ```bash
83
- python setup.py build_ext --inplace
84
- ```
85
-
86
- ### Usage
87
- from lqft_engine import AdaptiveLQFT
88
-
89
- # Initialize engine with an auto-migration threshold
90
- engine = AdaptiveLQFT(migration_threshold=50000)
91
-
92
- # Insert and Search
93
- engine.insert("secret_key", "confidential_data")
94
- result = engine.search("secret_key")
95
-
96
- print(f"Found: {result}")
@@ -1,96 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: lqft-python-engine
3
- Version: 0.1.8
4
- Summary: LQFT Engine: High-Performance Deduplicating Data Structure (V4.4 Stable)
5
- Home-page: https://github.com/ParjadM/Log-Quantum-Fractal-Tree-LQFT-
6
- Author: Parjad Minooei
7
- License: MIT
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.12
10
- Classifier: Operating System :: OS Independent
11
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
- Requires-Python: >=3.8
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE.md
15
- Requires-Dist: psutil
16
- Dynamic: author
17
- Dynamic: classifier
18
- Dynamic: description
19
- Dynamic: description-content-type
20
- Dynamic: home-page
21
- Dynamic: license
22
- Dynamic: license-file
23
- Dynamic: requires-dist
24
- Dynamic: requires-python
25
- Dynamic: summary
26
-
27
- # Log-Quantum Fractal Tree (LQFT) 🚀
28
-
29
- **Architect:** [Parjad Minooei](https://www.linkedin.com/in/parjadminooei)
30
- **Portfolio:** [parjadm.ca](https://www.parjadm.ca/)
31
-
32
- ---
33
-
34
- ## 📌 Executive Summary
35
-
36
- The **Log-Quantum Fractal Tree (LQFT)** is a high-performance, scale-invariant data structure engine designed for massive data deduplication and persistent state management. By bridging a **native C-Engine** with a **Python Foreign Function Interface (FFI)**, this project bypasses the Global Interpreter Lock (GIL) to achieve sub-microsecond search latencies and memory efficiency that scales with data entropy rather than data volume.
37
-
38
- ---
39
-
40
- ## 🧠 Formal Complexity Analysis
41
-
42
- As a Systems Architect, I have engineered the LQFT to move beyond the linear limitations of standard Python structures.
43
-
44
- ### 1. Time Complexity: $O(1)$ (Scale-Invariant)
45
- Unlike standard Trees ($O(\log N)$) or Lists ($O(N)$), the LQFT uses a fixed-depth 64-bit address space.
46
-
47
- * **Search/Insertion:** $O(1)$
48
- * **Mechanism:** The 64-bit hash is partitioned into 13 segments of 5-bits. This ensures that the path from the root to any leaf is physically capped at 13 hops, providing **deterministic latency** regardless of whether the database holds 1,000 or 1,000,000,000 items.
49
-
50
- ### 2. Space Complexity: $O(\Sigma)$ (Entropy-Based)
51
- Standard structures scale linearly based on the number of items ($N$). The LQFT scales based on the **Information Entropy** ($\Sigma$) of the dataset.
52
-
53
- * **Space:** $O(\Sigma)$
54
- * **Mechanism:** Utilizing **Merkle-DAG structural folding**, the engine detects identical data branches and reuses them in physical memory. In highly redundant datasets (e.g., DNA sequences or Log files), this results in sub-linear memory growth.
55
-
56
- ---
57
-
58
- ## 📊 Performance Benchmarks
59
- *Tested in Scarborough Lab: Python 3.12 | MinGW-w64 GCC-O3 Optimization*
60
-
61
- | Metric | Standard Python ($O(N)$) | LQFT C-Engine ($O(1)$) | Delta |
62
- | :--- | :--- | :--- | :--- |
63
- | **Search Latency (N=100k)** | ~3,564.84 μs | 0.50 μs | **7,129x Faster** |
64
- | **Insertion Time (N=100k)** | 41.05s | 1.07s | **38x Faster** |
65
- | **Memory (Versioning)** | $O(N \times V)$ | $O(\Sigma + V)$ | **99% Savings** |
66
-
67
- ---
68
-
69
- ## 🛠️ Architectural Pillars
70
-
71
- * **Native C-Engine Core:** Pushes memory allocation and bit-manipulation to the C-layer for hardware-level execution.
72
- * **Structural Folding:** A recursive structural hashing algorithm that collapses identical sub-trees into single pointers.
73
- * **Adaptive Migration:** A polymorphic wrapper (`AdaptiveLQFT`) that manages the transition from lightweight Python dictionaries to the heavy-duty C-Engine.
74
- * **Zero-Knowledge Integrity:** Fixed-depth pathing allows for 208-byte Merkle Proofs to verify data existence in microsecond time.
75
-
76
- ---
77
-
78
- ## ⚙️ Quick Start
79
-
80
- ### Compilation
81
- Ensure you have a C compiler (GCC/Clang) installed to build the FFI layer.
82
- ```bash
83
- python setup.py build_ext --inplace
84
- ```
85
-
86
- ### Usage
87
- from lqft_engine import AdaptiveLQFT
88
-
89
- # Initialize engine with an auto-migration threshold
90
- engine = AdaptiveLQFT(migration_threshold=50000)
91
-
92
- # Insert and Search
93
- engine.insert("secret_key", "confidential_data")
94
- result = engine.search("secret_key")
95
-
96
- print(f"Found: {result}")