Github user zsxwing commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6159#discussion_r30483774
  
    --- Diff: 
unsafe/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java ---
    @@ -162,6 +169,55 @@ public BytesToBytesMap(
        */
       public int size() { return size; }
     
    +  private static final class BytesToBytesMapIterator implements 
Iterator<Location> {
    +
    +    private final int numRecords;
    +    private final Iterator<MemoryBlock> dataPagesIterator;
    +    private final Location loc;
    +
    +    private int currentRecordNumber = 0;
    +    private Object pageBaseObject;
    +    private long offsetInPage;
    +
    +    BytesToBytesMapIterator(int numRecords, Iterator<MemoryBlock> 
dataPagesIterator, Location loc) {
    +      this.numRecords = numRecords;
    +      this.dataPagesIterator = dataPagesIterator;
    +      this.loc = loc;
    +      if (dataPagesIterator.hasNext()) {
    +        advanceToNextPage();
    +      }
    +    }
    +
    +    private void advanceToNextPage() {
    +      final MemoryBlock currentPage = dataPagesIterator.next();
    +      pageBaseObject = currentPage.getBaseObject();
    +      offsetInPage = currentPage.getBaseOffset();
    +    }
    +
    +    @Override
    +    public boolean hasNext() {
    +      return currentRecordNumber != numRecords;
    +    }
    +
    +    @Override
    +    public Location next() {
    --- End diff --
    
    The current implementation does not follow the javadoc of `Iterator`: 
`@throws NoSuchElementException if the iteration has no more elements`. 
However, it may be fine since it's an internal API.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to