3838 - [ ` bucket.toJSON() ` ] ( #buckettojson )
3939 - [ ` bucket.prettyPrint() ` ] ( #bucketprettyprint )
4040 - [ ` bucket.tableSize() ` ] ( #buckettablesize )
41- - [ ` hamt.isBucket(other) ` ] ( #hamtisbucketother )
4241 - [ Contribute] ( #contribute )
4342 - [ License] ( #license )
4443
5352### Example
5453
5554``` javascript
56- const hamt = require (' hamt-sharding' )
55+ const { createHAMT } = require (' hamt-sharding' )
5756const crypto = require (' crypto-promise' )
5857
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 ) => {
6160 return crypto
6261 .createHash (' sha256' )
63- .update (value )
62+ .update (buf )
6463 .digest ()
6564}
6665
67- const bucket = hamt ({
66+ const bucket = createHAMT ({
6867 hashFn: hashFn
6968})
7069
@@ -77,23 +76,23 @@ const output = await bucket.get('key')
7776## API
7877
7978``` javascript
80- const hamt = require (' hamt-sharding' )
79+ const { createHAMT } = require (' hamt-sharding' )
8180```
8281
8382### ` bucket.put(key, value) `
8483
8584``` javascript
86- const hamt = require (' hamt-sharding' )
87- const bucket = hamt ({... })
85+ const { createHAMT } = require (' hamt-sharding' )
86+ const bucket = createHAMT ({... })
8887
8988await bucket .put (' key' , ' value' )
9089```
9190
9291### ` bucket.get(key) `
9392
9493``` javascript
95- const hamt = require (' hamt-sharding' )
96- const bucket = hamt ({... })
94+ const { createHAMT } = require (' hamt-sharding' )
95+ const bucket = createHAMT ({... })
9796
9897await bucket .put (' key' , ' value' )
9998
@@ -103,8 +102,8 @@ console.info(await bucket.get('key')) // 'value'
103102### ` bucket.del(key) `
104103
105104``` javascript
106- const hamt = require (' hamt-sharding' )
107- const bucket = hamt ({... })
105+ const { createHAMT } = require (' hamt-sharding' )
106+ const bucket = createHAMT ({... })
108107
109108await bucket .put (' key' , ' value' )
110109await bucket .del (' key' , ' value' )
@@ -115,8 +114,8 @@ console.info(await bucket.get('key')) // undefined
115114### ` bucket.leafCount() `
116115
117116``` javascript
118- const hamt = require (' hamt-sharding' )
119- const bucket = hamt ({... })
117+ const { createHAMT } = require (' hamt-sharding' )
118+ const bucket = createHAMT ({... })
120119
121120console .info (bucket .leafCount ()) // 0
122121
@@ -128,8 +127,8 @@ console.info(bucket.leafCount()) // 1
128127### ` bucket.childrenCount() `
129128
130129``` javascript
131- const hamt = require (' hamt-sharding' )
132- const bucket = hamt ({... })
130+ const { createHAMT } = require (' hamt-sharding' )
131+ const bucket = createHAMT ({... })
133132
134133console .info (bucket .childrenCount ()) // 0
135134
@@ -142,8 +141,8 @@ console.info(bucket.childrenCount()) // 234 -- dependent on hashing algorithm
142141### ` bucket.eachLeafSeries() `
143142
144143``` javascript
145- const hamt = require (' hamt-sharding' )
146- const bucket = hamt ({... })
144+ const { createHAMT } = require (' hamt-sharding' )
145+ const bucket = createHAMT ({... })
147146
148147await bucket .put (' key' , ' value' )
149148
@@ -157,15 +156,6 @@ for await (const child of bucket.eachLeafSeries()) {
157156### ` bucket.toJSON() `
158157### ` bucket.prettyPrint() `
159158### ` 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- ```
169159
170160## Contribute
171161
0 commit comments