private void advanceToNextPage() {
            synchronized (this) {
                int nextIdx = dataPages.indexOf(currentPage) + 1;
                if (destructive && currentPage != null) {
                    dataPages.remove(currentPage);
                    freePage(currentPage);
                    nextIdx--;
                }
                if (dataPages.size() > nextIdx) {
                    currentPage = dataPages.get(nextIdx);
                    pageBaseObject = currentPage.getBaseObject();
                    offsetInPage = currentPage.getBaseOffset();
                    recordsInPage = Platform.getInt(pageBaseObject, offsetInPage);
                    offsetInPage += 4;
                } else {
                    currentPage = null;
                    if (reader != null) {
                        // remove the spill file from disk
                        try {
                            spillWriters.removeFirst().removeFile();
                        } catch (IOException e) {
                            logger.error("", e);
                        }
                    }
                    try {
                        Closeables.close(reader, /* swallowIOException = */ false);
                        reader = spillWriters.getFirst().getReader();
                        recordsInPage = -1;
                    } catch (IOException e) {
                        // Scala iterator does not handle exception
                        Platform.throwException(e);
                    }
                }
            }
        }
Returns the number of keys defined in the map.
indexr-query-opt/src/main/java/org/apache/spark/unsafe/map/BytesToBytesMap.java