aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2019-03-06 08:42:52 -0700
committerBen Johnson <benbjohnson@yahoo.com>2019-03-06 09:01:09 -0700
commitf615b9c78e712fa3728c3f3bddc800866f04ad98 (patch)
tree279a194452b8fbd8ed7f8114ac83fe742005d378 /README.md
parentMerge pull request #1 from benbjohnson/list-builder (diff)
downloadpds-f615b9c78e712fa3728c3f3bddc800866f04ad98.tar.gz
pds-f615b9c78e712fa3728c3f3bddc800866f04ad98.tar.xz
Add MapBuilder
This commit provides a `MapBuilder` for efficiently combining multiple `Map` mutations.
Diffstat (limited to 'README.md')
-rw-r--r--README.md21
1 files changed, 21 insertions, 0 deletions
diff --git a/README.md b/README.md
index fe862c4..653b9bb 100644
--- a/README.md
+++ b/README.md
@@ -212,6 +212,27 @@ iterate in the same order. Ordering can be insertion order dependent when two
keys generate the same hash.
+### Efficiently building maps
+
+If you are executing multiple mutations on a map, it can be much more efficient
+to use the `MapBuilder`. It uses nearly the same API as `Map` except that it
+updates a map in-place until you are ready to use it.
+
+```go
+b := immutable.NewMapBuilder(immutable.NewMap(nil))
+b.Set("foo", 100)
+b.Set("bar", 200)
+b.Set("foo", 300)
+
+m := b.Map()
+fmt.Println(m.Get("foo")) // "300"
+fmt.Println(m.Get("bar")) // "200"
+```
+
+Maps are safe to use even after you continue to use the builder. You can
+also build on top of existing maps too.
+
+
### Implementing a custom Hasher
If you need to use a key type besides `int`, `string`, or `[]byte` then you'll