diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2019-03-06 08:42:52 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2019-03-06 09:01:09 -0700 |
commit | f615b9c78e712fa3728c3f3bddc800866f04ad98 (patch) | |
tree | 279a194452b8fbd8ed7f8114ac83fe742005d378 /README.md | |
parent | Merge pull request #1 from benbjohnson/list-builder (diff) | |
download | pds-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.md | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -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 |