Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain map of BibEntry to index #13

Open
koppor opened this issue Aug 30, 2024 · 0 comments
Open

Maintain map of BibEntry to index #13

koppor opened this issue Aug 30, 2024 · 0 comments

Comments

@koppor
Copy link

koppor commented Aug 30, 2024

Assumption: entries are searched more often than added and removed. Then, it is "faster" to update indexes on entry addition/removed than "huge" search effort.

Currently, binarySearch is used. Which also should be fast for larger databases. If not, this issue provides a hint how to fix.

We tried with a first approach, but the indexes are not updated out of the list.

    private void initializeEntryIndexMap() {
        for (int i = 0; i < allEntries.size(); i++) {
            entryIndexMap.put(allEntries.get(i).getId(), i);
        }

        allEntries.addListener((ListChangeListener.Change<? extends BibEntry> c) -> {
            while (c.next()) {
                if (c.wasPermutated()) {
                    for (int i = c.getFrom(); i < c.getTo(); ++i) {
                        entryIndexMap.put(allEntries.get(i).getId(), i);
                    }
                } else {
                    if (c.wasRemoved()) {
                        for (BibEntry removedEntry : c.getRemoved()) {
                            entryIndexMap.remove(removedEntry.getId());
                        }
                    }
                    if (c.wasAdded()) {
                        for (int i = c.getFrom(); i < c.getTo(); ++i) {
                            entryIndexMap.put(allEntries.get(i).getId(), i);
                        }
                    }
                }
            }
        });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant