Skip to content

Unnecessary to check levelnumber = = 0 in Level.java #118

@hecenjie

Description

@hecenjie
// Version.java
    public LookupResult get(LookupKey key)
    {
        LookupResult lookupResult = level0.get(key, readStats);
        if (lookupResult == null) {
            for (Level level : levels) {
                lookupResult = level.get(key, readStats);
                ...
            }
        }
        ...
        return lookupResult;
    }

// Level0.java
    public LookupResult get(LookupKey key, ReadStats readStats)
    {
        ...
        List<FileMetaData> fileMetaDataList = new ArrayList<>(files.size());
        for (FileMetaData fileMetaData : files) {
            if (...) {
                fileMetaDataList.add(fileMetaData);
            }
        }
        Collections.sort(fileMetaDataList, NEWEST_FIRST);
        ...
    }

// Level.java
    public LookupResult get(LookupKey key, ReadStats readStats)
    {
        ...
        List<FileMetaData> fileMetaDataList = new ArrayList<>(files.size());
        if (levelNumber == 0) {    // Do we really need to judge this condition ?
            for (FileMetaData fileMetaData : files) {
                if (...) {
                    fileMetaDataList.add(fileMetaData);
                }
            }
        }
        else {
            // Binary search to find earliest index whose largest key >= ikey.
        }
        ...
    }

In the above function, level0.get() and level.get() are called respectively. However, In the implementation of the former, calls the sort function Collections.sort(fileMetaDataList, NEWEST_FIRST); to make the newer files in front of the list while the other call doesn't. So do we need this sort function call or not? And why get function in Level.java should consider the situation of level0?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions