github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/sets/bitset/iterator.go (about)

     1  package bitset
     2  
     3  // Iterator is an iterator over a Set.
     4  type Iterator struct {
     5  	index int
     6  
     7  	set *Set
     8  }
     9  
    10  // Valid returns true if the iterator is positioned at a valid element.
    11  func (it *Iterator) Valid() bool {
    12  	return it.index < it.set.arr.Size()
    13  }
    14  
    15  // Move moves the iterator to the next element.
    16  func (it *Iterator) Move() {
    17  	for it.Valid() && it.set.arr.Get(it.index) == false {
    18  		it.index++
    19  	}
    20  }
    21  
    22  // Get returns the current element.
    23  func (it *Iterator) Get() int {
    24  	return it.index
    25  }
    26  
    27  // Remove removes the current element from the Set.
    28  func (it *Iterator) Remove() {
    29  	it.set.Remove(it.index)
    30  }