Skip to content

Commit

Permalink
Add *Update methods to update an existing tag (#24)
Browse files Browse the repository at this point in the history
This is useful to avoid a double lookup: once to find the current
value, the second time to update its value. The tag could be a counter
we want to update or, with the generics tree, any struct/map.

`SetOrUpdate()` is the same as `Set()`, but when there already is a
tag, it is passed to the provided update function instead of being
replaced by the provided tag value. If no match, the provided tag
value is used instead.

`AddOrUpdate()` is the same as `Add()` and works like `Set()` except
it will append a tag (when no match) or modify the first matching
tag (when there is a match).

Both functions take a tag value which is used when the existing tag
does not exist (no tag for `SetOrUpdate()` or no matching tag for
`AddOrUpdate()`). Both functions take an update function which is used
when there is an existing tag and the update function is applied on
the existing tag to get another tag. The provided tag is therefore
ignored in this case.
  • Loading branch information
vincentbernat authored Oct 21, 2023
1 parent 2e9139d commit 96387d0
Show file tree
Hide file tree
Showing 63 changed files with 2,271 additions and 1,569 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A Go implemenation of a [patricia tree](https://en.wikipedia.org/wiki/Radix_tree
tagging IPv4 and IPv6 addresses with CIDR bits, with a focus on producing as little garbage for the garbage collector to
manage as possible. This allows you to tag millions of IP addresses without incurring a penalty during GC scanning.

This library requires Go >= 1.18. Check version [1.1.0](https://github.com/kentik/patricia/releases/tag/v1.1.0) if you wish to use a prrio version.
This library requires Go >= 1.18. Check version [1.1.0](https://github.com/kentik/patricia/releases/tag/v1.1.0) if you wish to use an older version.

IP/CIDR tagging
---------------
Expand Down
88 changes: 49 additions & 39 deletions bool_tree/tree_v4.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 49 additions & 39 deletions bool_tree/tree_v6_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 96387d0

Please sign in to comment.