Skip to content

This repository contains a modified implementation of the build-in PriorityQueue java class. It combines a HashMap with it, to allow O(1) for contains.

License

Notifications You must be signed in to change notification settings

axel7083/ModifiedPriorityQueue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ModifiedPriorityQueue

This repository contains a modified implementation of the build-in PriorityQueue java class. It combines a HashMap with it, to allow O(1) for contains.

Here is the medium article I wrote corresponding to this repository.

Usage

You can use your own Comparator as a constructor argument.

kBest represents the number of elements you want to keep.

ModifiedPriorityQueue<Integer> mPQueue = new ModifiedPriorityQueue<Integer>(kBest);
for(int val : data)
    if(mPQueue.size() < kBest)
        mPQueue.add(val);
    else {
        int first = mPQueue.peek();
        if(val > first)
            mPQueue.add(val);
    }      

About

This repository contains a modified implementation of the build-in PriorityQueue java class. It combines a HashMap with it, to allow O(1) for contains.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages