@fraczak/k 8.0.0 → 8.1.0

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,30 @@ All notable changes to this project will be documented here.
5
5
  The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
  This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [8.1.0] — 2026-10-20 — Dynamic JSON Bit-Trie & json? Standard Library
9
+
10
+ ### Dynamic JSON (djson) Consolidation
11
+
12
+ - **Unified Binary Bit-Trie Representation**:
13
+ - Consolidated all dynamic JSON approaches onto the binary bit-trie
14
+ implementation (`btrie[V]`), eliminating linear cons-lists and
15
+ heap allocations in dynamic document navigation.
16
+ - Standardized `Examples/djson.k` as the single dynamic JSON
17
+ specification and `codecs/djson.mjs` (`k-djson`) as its codec.
18
+ - Retired obsolete cons-list and Patricia trie dynamic JSON
19
+ variants (`djson-btrie.k`, `djson-ptrie.k`, `djson-btrie.mjs`,
20
+ `djson-ptrie.mjs`, `k-djson-btrie`, `k-djson-ptrie`).
21
+ - **Complete Standard Library on `json?`**:
22
+ - Implemented standard dynamic JSON methods in `Examples/djson.k`
23
+ operating directly on the universal `json?` type:
24
+ * Object operations: `get`, `has?`, `set`, `del`
25
+ * List operations: `nth`, `has_index?`, `set_nth`, `del_nth`,
26
+ `push`
27
+ * Enumerations: `keys`, `keys_raw`, `values`, `values_raw`
28
+ * Cardinality: `length` (JSON float64 number), `length_nat`
29
+ (`bits?`)
30
+ * Type inspection: `type_of` and `is_*?` predicates
31
+
8
32
  ## [8.0.0] — 2026-10-20 — Named Patterns, Type Schemes & Trie Codecs
9
33
 
10
34
  ### Language & Type System
package/DOCS/CODECS.md CHANGED
@@ -158,32 +158,30 @@ The `codecs/` directory provides the following standard codecs:
158
158
  - JSON objects map directly to products `{ field: val, ... }`.
159
159
  - JSON arrays map to indexed products `{ "0": a0, "1": a1, ... }`.
160
160
  - Ideal for record-oriented projection (e.g. `.user .name`).
161
- - **`djson.mjs` (`k-djson`) — Universal Dynamic JSON (Cons-List)**:
162
- Maps every JSON document to a single universal recursive named pattern
163
- `djson[]`:
161
+ - **`djson.mjs` (`k-djson`) — Universal Dynamic JSON (Binary Bit-Trie)**:
162
+ Maps every JSON document to a single universal recursive named
163
+ pattern `djson[]`:
164
164
  ```k
165
+ btrie[V] = < {} nil, { opt[V] val, T 0, T 1 } trie > = T;
166
+
165
167
  djson[] = <
166
- float64 number,
167
- str string,
168
- < {} true, {} false > bool,
168
+ number[] number,
169
+ string[] string,
170
+ bool[] bool,
169
171
  {} null,
170
- < {} nil, { J car, L cdr } cons > = L list,
171
- < {} nil, { { str key, J val } car, O cdr } cons > = O object
172
+ btrie[J] list,
173
+ btrie[J] object
172
174
  > = J;
173
175
  ```
174
- Because every JSON value shares the exact same static 29-node pattern,
175
- a `k` relation can be compiled once against `djson[]` and process
176
- arbitrary JSON documents of any shape or array/object length.
177
- - **`djson-btrie.mjs` (`k-djson-btrie`) — Binary Bit-Trie Dynamic JSON**:
178
- Replaces the linear `list` and `object` cons-lists with a unified
179
- 27-node binary bit-trie (`TRIE`). Array indices (`bits?`) and string
180
- keys are stored along MSB-to-LSB bit paths, enabling $O(|K|)$ lookup
181
- (`dot` and `nth` in `Examples/djson-btrie.k`) via direct `.0`/`.1`
182
- projections with zero character-equality checks.
183
- - **`djson-ptrie.mjs` (`k-djson-ptrie`) — Patricia/Radix Dynamic JSON**:
184
- Models `list` and `object` as path-compressed radix tries (`trie-array`
185
- style) with `prefix` and $O(1)$ subtree `size` (`list_size` and
186
- `obj_size` in `Examples/djson-ptrie.k`).
176
+ Uses a unified 27-node binary bit-trie for both arrays and objects.
177
+ Array indices (`bits?`) and string keys are stored along MSB-to-LSB
178
+ bit paths, enabling $O(|K|)$ lookup via direct `.0`/`.1` projections
179
+ with zero allocations and zero character-equality loops.
180
+ Accompanied by a complete standard library on `json?` in
181
+ [`Examples/djson.k`](../Examples/djson.k) (`get`, `nth`, `has?`,
182
+ `has_index?`, `set`, `del`, `set_nth`, `del_nth`, `push`, `keys`,
183
+ `keys_raw`, `values`, `values_raw`, `length`, `length_nat`,
184
+ `type_of`).
187
185
 
188
186
  ## Testing a Codec
189
187
 
@@ -218,9 +216,9 @@ npm test
218
216
  ## Web REPL (VFS) Bundling
219
217
 
220
218
  When `repl.html` is generated (`npm run build:repl-html`):
221
- - Codecs (`int.mjs`, `json.mjs`, `djson.mjs`, `djson-btrie.mjs`,
222
- `djson-ptrie.mjs`, `utf8.mjs`, `unit.mjs`, `ieee.mjs`) are bundled into
223
- 100% self-contained ES modules with zero imports.
219
+ - Codecs (`int.mjs`, `json.mjs`, `djson.mjs`, `utf8.mjs`, `unit.mjs`,
220
+ `ieee.mjs`) are bundled into 100% self-contained ES modules with zero
221
+ imports.
224
222
  - `runCodecCLI` is shimmed as a no-op, and `Value` helpers are directly
225
223
  inlined.
226
224
  - In the browser, the VFS serves these self-contained modules directly to
@@ -213,9 +213,7 @@ To make `codecs/` intuitive and self-contained:
213
213
  codecs/
214
214
  ├── int.mjs # Integer & list codec
215
215
  ├── json.mjs # JSON codec (schema-specializing)
216
- ├── djson.mjs # Dynamic JSON codec (cons-list)
217
- ├── djson-btrie.mjs # Dynamic JSON codec (binary bit-trie)
218
- ├── djson-ptrie.mjs # Dynamic JSON codec (Patricia/radix trie)
216
+ ├── djson.mjs # Dynamic JSON codec (binary bit-trie)
219
217
  ├── utf8.mjs # UTF-8 string codec
220
218
  ├── utf16.mjs # UTF-16 string codec
221
219
  ├── ieee.mjs # IEEE 754 float codec
@@ -244,8 +242,8 @@ In the browser REPL (`repl.html`):
244
242
  imports**.
245
243
  - **No Runtime Files in VFS**: `codecs/runtime/*` is not included in the
246
244
  browser VFS. The VFS only contains verified, self-contained user-facing
247
- files (`int.mjs`, `json.mjs`, `djson.mjs`, `djson-btrie.mjs`,
248
- `djson-ptrie.mjs`, `utf8.mjs`, `unit.mjs`, `ieee.mjs`).
245
+ files (`int.mjs`, `json.mjs`, `djson.mjs`, `utf8.mjs`, `unit.mjs`,
246
+ `ieee.mjs`).
249
247
  - **Native Browser Loading**: In `repl-codecs.mjs`, the browser reads the
250
248
  codec source from VFS, wraps it in a Blob, and invokes native `await
251
249
  import(blobUrl)`. No regex manipulation, import stripping, or global
@@ -1,26 +1,22 @@
1
1
  # Comparison of JSON Approaches in k
2
2
 
3
- This document compares the four JSON codec and schema implementations in
4
- the **k** repository:
3
+ > [!NOTE]
4
+ > **Resolution**: The **binary bit-trie** was selected and standardized
5
+ > as the sole dynamic JSON implementation in `codecs/djson.mjs` and
6
+ > `Examples/djson.k`. The cons-list and Patricia trie implementations
7
+ > were removed. This document preserves the architectural comparison
8
+ > and benchmark findings that guided this design decision.
9
+
10
+ This document compares the JSON codec and schema implementations:
5
11
 
6
12
  1. **Schema-Specializing JSON** (`json`):
7
13
  [`codecs/json.mjs`][json-mjs]
8
- 2. **Dynamic Cons-List JSON** (`djson`):
14
+ 2. **Universal Dynamic JSON (Binary Bit-Trie)** (`djson`):
9
15
  [`codecs/djson.mjs`][djson-mjs] & [`Examples/djson.k`][djson-k]
10
- 3. **Dynamic Binary Bit-Trie JSON** (`djson-btrie`):
11
- [`codecs/djson-btrie.mjs`][djson-btrie-mjs] &
12
- [`Examples/djson-btrie.k`][djson-btrie-k]
13
- 4. **Dynamic Patricia/Radix Trie JSON** (`djson-ptrie`):
14
- [`codecs/djson-ptrie.mjs`][djson-ptrie-mjs] &
15
- [`Examples/djson-ptrie.k`][djson-ptrie-k]
16
16
 
17
17
  [json-mjs]: file:///home/wojtek/gits/K/k/codecs/json.mjs
18
18
  [djson-mjs]: file:///home/wojtek/gits/K/k/codecs/djson.mjs
19
19
  [djson-k]: file:///home/wojtek/gits/K/k/Examples/djson.k
20
- [djson-btrie-mjs]: file:///home/wojtek/gits/K/k/codecs/djson-btrie.mjs
21
- [djson-btrie-k]: file:///home/wojtek/gits/K/k/Examples/djson-btrie.k
22
- [djson-ptrie-mjs]: file:///home/wojtek/gits/K/k/codecs/djson-ptrie.mjs
23
- [djson-ptrie-k]: file:///home/wojtek/gits/K/k/Examples/djson-ptrie.k
24
20
 
25
21
  ---
26
22
 
@@ -112,10 +112,9 @@ The bundled VFS and UI examples must include only verified useful files:
112
112
 
113
113
  #### 1. Curated Files Explorer
114
114
  In the Web REPL "Files" (VFS) explorer, the visible files are strictly curated to verified examples and codecs:
115
- - **k-codes**: `core.k`, `arithmetics.k`, `ieee.k`, `djson.k`,
116
- `djson-btrie.k`, `djson-ptrie.k`
117
- - **codecs**: `json.mjs`, `djson.mjs`, `djson-btrie.mjs`,
118
- `djson-ptrie.mjs`, `utf8.mjs`, `int.mjs`, `unit.mjs`, `ieee.mjs`
115
+ - **k-codes**: `core.k`, `arithmetics.k`, `ieee.k`, `djson.k`
116
+ - **codecs**: `json.mjs`, `djson.mjs`, `utf8.mjs`, `int.mjs`, `unit.mjs`,
117
+ `ieee.mjs`
119
118
  - User-created or uploaded files remain visible.
120
119
  - Internal runtime artifacts (`backends/wasm/runtime.wat`) and redundant directory prefixes (`Examples/`, `codecs/`) are kept accessible internally but hidden from the default file listing.
121
120
  - Clicking "Load" on a `.mjs` file automatically executes `:codec load <filename>`.