38
38
- [ ` bucket.toJSON() ` ] ( #buckettojson )
39
39
- [ ` bucket.prettyPrint() ` ] ( #bucketprettyprint )
40
40
- [ ` bucket.tableSize() ` ] ( #buckettablesize )
41
- - [ ` hamt.isBucket(other) ` ] ( #hamtisbucketother )
42
41
- [ Contribute] ( #contribute )
43
42
- [ License] ( #license )
44
43
53
52
### Example
54
53
55
54
``` javascript
56
- const hamt = require (' hamt-sharding' )
55
+ const { createHAMT } = require (' hamt-sharding' )
57
56
const crypto = require (' crypto-promise' )
58
57
59
- // decide how to hash things , can return a Promise
60
- const hashFn = async (value ) => {
58
+ // decide how to hash buffers made from keys , can return a Promise
59
+ const hashFn = async (buf ) => {
61
60
return crypto
62
61
.createHash (' sha256' )
63
- .update (value )
62
+ .update (buf )
64
63
.digest ()
65
64
}
66
65
67
- const bucket = hamt ({
66
+ const bucket = createHAMT ({
68
67
hashFn: hashFn
69
68
})
70
69
@@ -77,23 +76,23 @@ const output = await bucket.get('key')
77
76
## API
78
77
79
78
``` javascript
80
- const hamt = require (' hamt-sharding' )
79
+ const { createHAMT } = require (' hamt-sharding' )
81
80
```
82
81
83
82
### ` bucket.put(key, value) `
84
83
85
84
``` javascript
86
- const hamt = require (' hamt-sharding' )
87
- const bucket = hamt ({... })
85
+ const { createHAMT } = require (' hamt-sharding' )
86
+ const bucket = createHAMT ({... })
88
87
89
88
await bucket .put (' key' , ' value' )
90
89
```
91
90
92
91
### ` bucket.get(key) `
93
92
94
93
``` javascript
95
- const hamt = require (' hamt-sharding' )
96
- const bucket = hamt ({... })
94
+ const { createHAMT } = require (' hamt-sharding' )
95
+ const bucket = createHAMT ({... })
97
96
98
97
await bucket .put (' key' , ' value' )
99
98
@@ -103,8 +102,8 @@ console.info(await bucket.get('key')) // 'value'
103
102
### ` bucket.del(key) `
104
103
105
104
``` javascript
106
- const hamt = require (' hamt-sharding' )
107
- const bucket = hamt ({... })
105
+ const { createHAMT } = require (' hamt-sharding' )
106
+ const bucket = createHAMT ({... })
108
107
109
108
await bucket .put (' key' , ' value' )
110
109
await bucket .del (' key' , ' value' )
@@ -115,8 +114,8 @@ console.info(await bucket.get('key')) // undefined
115
114
### ` bucket.leafCount() `
116
115
117
116
``` javascript
118
- const hamt = require (' hamt-sharding' )
119
- const bucket = hamt ({... })
117
+ const { createHAMT } = require (' hamt-sharding' )
118
+ const bucket = createHAMT ({... })
120
119
121
120
console .info (bucket .leafCount ()) // 0
122
121
@@ -128,8 +127,8 @@ console.info(bucket.leafCount()) // 1
128
127
### ` bucket.childrenCount() `
129
128
130
129
``` javascript
131
- const hamt = require (' hamt-sharding' )
132
- const bucket = hamt ({... })
130
+ const { createHAMT } = require (' hamt-sharding' )
131
+ const bucket = createHAMT ({... })
133
132
134
133
console .info (bucket .childrenCount ()) // 0
135
134
@@ -142,8 +141,8 @@ console.info(bucket.childrenCount()) // 234 -- dependent on hashing algorithm
142
141
### ` bucket.eachLeafSeries() `
143
142
144
143
``` javascript
145
- const hamt = require (' hamt-sharding' )
146
- const bucket = hamt ({... })
144
+ const { createHAMT } = require (' hamt-sharding' )
145
+ const bucket = createHAMT ({... })
147
146
148
147
await bucket .put (' key' , ' value' )
149
148
@@ -157,15 +156,6 @@ for await (const child of bucket.eachLeafSeries()) {
157
156
### ` bucket.toJSON() `
158
157
### ` bucket.prettyPrint() `
159
158
### ` bucket.tableSize() `
160
- ### ` hamt.isBucket(other) `
161
-
162
- ``` javascript
163
- const hamt = require (' hamt-sharding' )
164
- const bucket = hamt ({... })
165
-
166
- console .info (hamt .isBucket (bucket)) // true
167
- console .info (hamt .isBucket (true )) // false
168
- ```
169
159
170
160
## Contribute
171
161
0 commit comments