rfc:arrayiterator-improvements

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:arrayiterator-improvements [2016/11/24 21:01] – Changed seekKey() to throw. wesnetmorfc:arrayiterator-improvements [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 17: Line 17:
 The existing method ''ArrayIterator::seek($position)'' searches for the Entry in a linear manner, and this is not ideal for many uses, as what it does is simply iterating over the array (or part of it) to reach the specified position (or key, assuming the array is a list). Instead, the proposed method ''ArrayIterator::seekKey($key)'' would be a ''O(1)'' operation as the cursor can immediately jump to the Entry identified by the given ''$key''. The existing method ''ArrayIterator::seek($position)'' searches for the Entry in a linear manner, and this is not ideal for many uses, as what it does is simply iterating over the array (or part of it) to reach the specified position (or key, assuming the array is a list). Instead, the proposed method ''ArrayIterator::seekKey($key)'' would be a ''O(1)'' operation as the cursor can immediately jump to the Entry identified by the given ''$key''.
  
-Specifically, if the given key is present in the array the method would successfully return ''null''; subsequent calls to ''ArrayIterator::current()'' would get the value associated with the specified ''$key'', ''ArrayIterator::key()'' would get ''$key'' and so on, like it would normally behave when iterating over the Entry. Instead, if the provided key is not present in the array, and exactly like ''ArrayIterator::seek($position)'', the method would throw a ''OutOfBoundsException'' and keep the current ''ArrayIterator'''s cursor state.+Specifically, if the given key is present in the array the method would successfully execute such that subsequent calls to ''ArrayIterator::current()'' would get the value associated with the specified ''$key'', ''ArrayIterator::key()'' would get ''$key'' and so on, like it would normally behave when iterating over the Entry. Instead, if the provided key is not present in the array, and exactly like ''ArrayIterator::seek($position)'', the method would throw a ''OutOfBoundsException'' and keep the current ''ArrayIterator'''s cursor state.
  
 ===== ArrayIterator::prev():void ===== ===== ArrayIterator::prev():void =====
  
-This method would simply move the Iterator's cursor to the previous Entry in the hash table's linked list. Exactly like ''ArrayIterator::next()'', it would never throw and it would always return ''null'', but if there is no previous Entry, after calling it, a call to the ''valid()'' method would return ''false''.+This method would simply move the Iterator's cursor to the previous Entry in the hash table's linked list. Exactly like ''ArrayIterator::next()'', it would never throw and it would always return ''null''. However, if there is no previous Entry, immediate calls to the ''valid()'' method would return ''false''. 
 + 
 + 
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
rfc/arrayiterator-improvements.1480021279.txt.gz · Last modified: 2017/09/22 13:28 (external edit)