-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Range
method
#102
Add Range
method
#102
Conversation
gozeloglu
commented
Apr 29, 2023
- This fixes Add Range/ForEach method #71.
- The code has not been tested yet. I need some help from you, @swithek. How can I test this code?
* This fixes jellydator#71. * The code is not tested. Signed-off-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
@gozeloglu three PRs in a row, you're on fire! As for testing, I think something like this should work: c := prepCache("1", "2", "3", "4", "5")
var results []string
c.Range(func(item *Item) {
results = append(results, item.Key())
return item.Key() != "4"
})
assert.Equal(t, []string{"1", "2", "3", "4"}, results) // order is important |
Signed-off-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
I added a simple test but I only checked the "5" because of map internal. |
Hi @swithek. Can you review the last changes? |
@gozeloglu sorry for the delay. I'll review your changes sometime in the next few days. |
My proposal in the comment above uses the LRU list instead of the map, so you should be able to get predictable results and check all items in the result slice. @gozeloglu |
* For loop changed. * Test case updated. Signed-off-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
I updated the test. The keys are added to the front of the linked list. So, I checked in reverse order. |
* RLock() before for loop, re-RLock inside for loop. Signed-off-by: Gökhan Özeloğlu <gozeloglu@gmail.com>