-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing Map.Drain API to traverse a map while also deleting entries
This commit introduces the `Map.Drain` API to traverse the map while also removing its entries. It leverages the same `MapIterator` structure, with the introduction of a new unexported method to handle the map draining. The tests make sure that the behavior is as expected, and that this API returns an error while invoked on the wrong map, such as arrays, for which `Map.Iterate` should be used instead. To support the adoption of the `LookupAndDelete` system call at different kernel releases (e.g., queues and hash support this operation from different kernel versions), this implementation introduces a fallback method to iterate through the map using the sequential `Lookup` -> `Delete` operations. As for the `MapIterate.Next`, concurrent operations might modify/remove entries, but the method would try to check whether there is more data to lookup in the map and proceed without failing (e.g., key removed in the meantime doesn't necessarily mean that it should fail, instead try with `nextKey`). From the user perspective, the usage should be similar to `Map.Iterate`, as shown as follows: ```go m, err := NewMap(&MapSpec{ Type: Hash, KeySize: 4, ValueSize: 8, MaxEntries: 10, }) // populate here the map and defer close it := m.Drain() for it.Next(keyPtr, &value) { // here the entry doesn't exist anymore in the underlying map. ... } ``` Signed-off-by: Simone Magnani <[email protected]>
- Loading branch information
1 parent
2613a2c
commit 3d9f4e0
Showing
2 changed files
with
312 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters