SetNext moves to next element and returns true if it exists.
()
| 61 | |
| 62 | // SetNext moves to next element and returns true if it exists. |
| 63 | func (it *EntryInfoIterator) SetNext() bool { |
| 64 | it.mutex.Lock() |
| 65 | |
| 66 | it.valid = false |
| 67 | it.currentIndex++ |
| 68 | |
| 69 | if it.elementsCount > it.currentIndex { |
| 70 | it.valid = true |
| 71 | |
| 72 | empty := it.setCurrentEntry() |
| 73 | it.mutex.Unlock() |
| 74 | |
| 75 | if empty { |
| 76 | return it.SetNext() |
| 77 | } |
| 78 | return true |
| 79 | } |
| 80 | |
| 81 | for i := it.currentShard + 1; i < it.cache.config.Shards; i++ { |
| 82 | it.elements, it.elementsCount = it.cache.shards[i].copyHashedKeys() |
| 83 | |
| 84 | // Non empty shard - stick with it |
| 85 | if it.elementsCount > 0 { |
| 86 | it.currentIndex = 0 |
| 87 | it.currentShard = i |
| 88 | it.valid = true |
| 89 | |
| 90 | empty := it.setCurrentEntry() |
| 91 | it.mutex.Unlock() |
| 92 | |
| 93 | if empty { |
| 94 | return it.SetNext() |
| 95 | } |
| 96 | return true |
| 97 | } |
| 98 | } |
| 99 | it.mutex.Unlock() |
| 100 | return false |
| 101 | } |
| 102 | |
| 103 | func (it *EntryInfoIterator) setCurrentEntry() bool { |
| 104 | var entryNotFound = false |