serializable-bptree 6.1.0 → 6.2.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/README.md CHANGED
@@ -72,7 +72,15 @@ tree.clear()
72
72
 
73
73
  Firstly, in most cases, there is no need to use a B+tree in JavaScript. This is because there is a great alternative, the Map object. Nonetheless, if you need to retrieve values in a sorted order, a B+tree can be a good solution. These cases are often related to databases, and you may want to store this state not just in memory, but on a remote server or in a file. In this case, **serializable-bptree** can help you.
74
74
 
75
- Additionally, this library supports asynchronous operations. Please refer to the section below for instructions on using it asynchronously.
75
+ Additionally, this library supports asynchronous operations and rule-based query optimization for multi-index scenarios. Please refer to the sections below for more details.
76
+
77
+ ## Key Features
78
+
79
+ - **Serializable**: Save and load the B+Tree state to/from any storage (File, DB, Memory, etc.).
80
+ - **Duplicate Values**: Naturally handles duplicate values.
81
+ - **Async/Sync Support**: Provides both synchronous and asynchronous APIs.
82
+ - **Query Optimization**: Rule-based optimizer to choose the best index for complex queries.
83
+ - **TypeScript**: Fully typed for a better developer experience.
76
84
 
77
85
  ## How to use
78
86
 
@@ -105,7 +113,7 @@ import {
105
113
  ValueComparator,
106
114
  NumericComparator,
107
115
  StringComparator
108
- } from 'https://cdn.jsdelivr.com/npm/serializable-bptree@6/+esm'
116
+ } from 'https://cdn.jsdelivr.net/npm/serializable-bptree@6/+esm'
109
117
  </script>
110
118
  ```
111
119
 
@@ -122,6 +130,30 @@ Explore the detailed guides and concepts of `serializable-bptree`:
122
130
  - **Advanced Topics**
123
131
  - [Duplicate Value Handling](./docs/DUPLICATE_VALUES.md): Strategies for managing large amounts of duplicate data.
124
132
  - [Concurrency & Synchronization](./docs/CONCURRENCY.md): Multi-instance usage and locking mechanisms.
133
+ - [Query Optimization Guide](./docs/QUERY.md#performance--optimization): How to use `ChooseDriver`, `get()`, and `verify()` for complex queries.
134
+
135
+ ## Quick Example: Query Optimization
136
+
137
+ When you have multiple indexes (e.g., an index for `id` and another for `age`), you can use `ChooseDriver` to select the most efficient index for your query.
138
+
139
+ ```typescript
140
+ const query = { id: { equal: 100 }, age: { gt: 20 } }
141
+
142
+ // 1. Select the best index based on condition priority
143
+ const driver = BPTreeSync.ChooseDriver([
144
+ { tree: idxId, condition: query.id },
145
+ { tree: idxAge, condition: query.age }
146
+ ])
147
+
148
+ // 2. Execute query using the selected driver
149
+ for (const [pk, val] of driver.tree.whereStream(driver.condition)) {
150
+ // 3. Filter other conditions using get() and verify()
151
+ const age = idxAge.get(pk)
152
+ if (age !== undefined && idxAge.verify(age, query.age)) {
153
+ console.log(`Match found! PK: ${pk}`)
154
+ }
155
+ }
156
+ ```
125
157
 
126
158
  ## Migration from v5.x.x to v6.0.0
127
159