Sites where you can find me or my work | |
---|---|
Web and social media | |
Software development | |
Publications |
If you want to generate the equivalent to the above for your own GitHub profile, check out the cicirello/user-statistician GitHub Action.
Utilities and data structures used by several of my projects
Home Page: https://core.cicirello.org
License: GNU General Public License v3.0
Sites where you can find me or my work | |
---|---|
Web and social media | |
Software development | |
Publications |
If you want to generate the equivalent to the above for your own GitHub profile, check out the cicirello/user-statistician GitHub Action.
The current retainAll has a runtime of O(n + m + (n-m) lg n). The (n-m) lg n term comes from making (n-m) calls to remove(Object). We can eliminate that term with an alternative approach that instead rebuilds the heap with the elements we're keeping. This will be O(n+m).
FibonacciHeapDouble has a redundant implements declaration, a remnant of before superclass was introduced.
Describe the bug
Copying empty Fibonacci heap throws null pointer exception.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Copying empty heap should give empty heap.
The PriorityQueueNode class is immutable external to its package. For this reason it was assumed safe to directly store instances passed as parameters without copying them as well as to return references to instances.
However, if someone peeks an instance from one heap and then offers it to another heap, two heaps would end up sharing instances. Or if someone offers the same instance to two binary heaps. This is potentially problematic in the case of changing a priority. Change priority in one heap and the value changes in both but one will be structurally invalid.
It should be sufficient to fix where PriorityQueueNode is a parameter such as in offer method, add method, addAll method, and constructors.
Some methods of the PriorityQueueDouble interface have documentation that indicates that elements are only added if distinct, documenting exceptions, etc. This is currently true of all of the existing implementations. However, new classes are planned (see #101 and #102) that will allow duplicate elements. Move the documentation of distinctness into the specific implementations that require it, and edit the interface docs to be more general.
Some methods of the PriorityQueue interface have documentation that indicates that elements are only added if distinct, documenting exceptions, etc. This is currently true of all of the existing implementations. However, new classes are planned (see #101 and #102) that will allow duplicate elements. Move the documentation of distinctness into the specific implementations that require it, and edit the interface docs to be more general.
The current retainAll has a runtime of O(n + m + (n-m) lg n). The (n-m) lg n term comes from making (n-m) calls to remove(Object). We can eliminate that term with an alternative approach that instead rebuilds the heap with the elements we're keeping. This will be O(n+m).
Summary
An implementation of a partially filled array of primitive double values. Should have similar methods to Java's ArrayList class where possible but without using wrapper objects.
Edit javadoc comments in priority queue interfaces and classes to clean up cases of overriding method just to add doc details, and other messiness.
Summary
Enable test coverage reporting on repo.
BinaryHeapDouble currently relies on the default implementation of the addAll(Collection) method, which simply calls the add method repeatedly, for a worst case runtime of O(m lg (n+m)) where m elements are added to a heap that currently has n elements. This is fine for small m, but in the case where many elements are added at once, this can be improved to O(n + m) by inserting the m new elements arbitrarily into the end of the array and then rebuilding the heap.
Add a method to the BinaryHeapDouble class for merging heaps.
Modify PriorityQueue.change to return a boolean indicating if anything changed.
BinaryHeap currently relies on default implementation of removeAll(Collection) which simply calls the remove(Object) method once for each element in the Collection. The runtime of this approach is O(m lg n) where the heap currently has n elements and you are removing m of them. This can be improved to O(n + m) for the case when there are many to remove by rebuilding the heap with only the elements that you want to keep. If a relatively small number are to be removed, the current behavior is still faster. Reimplement with the O(n + m) approach, with a comment related to the small number of removals case.
Summary
Add an implementation of disjoint set forests, which is needed for planned functionality in dependent libraries. Include the following variations:
The PriorityQueue and PriorityQueueDouble interfaces currently have a change method that can be used to change the priority of an element in the priority queue. This method supports both increasing and decreasing priority. Add a promote method that will only decrease priority for a min-heap or increase for a max-heap, otherwise doing nothing if the new priority is in opposite direction. Similarly add a demote method that does the opposite.
Implement the new interface methods in the binary heap and Fibonacci heap implementations.
There is much redundant code between FibonacciHeapDouble and SimpleFibonacciHeapDouble. Refactor FibonacciHeapDouble to extend SimpleFibonacciHeapDouble.
Add a Fibonacci heap implementation of the IntPriorityQueueDouble interface.
Add a method to the FibonacciHeap class for merging heaps.
FibonacciHeapDouble class overrides package access methods without @Override
annotations.
Is your feature request related to a problem? Please describe.
Some applications of priority queue may involve adding a new element, while removing the next in priority order. This can obviously be done with a pair of calls to the existing poll() and offer() methods. But for some implementations of a priority queue, there may be a more efficient approach to the combination. E.g., For a binary heap, you can save the root temporarily, insert new element at root, percolate it down the heap, and then return the old root. This would be approximately half the work of the poll() then offer() alternative.
Describe the solution you'd like
A method, perhaps called pollThenOffer() or pollThenAdd() that does the combination of polling the next element in priority order, while adding the new element. Probably pollThenAdd() since the add() methods through an exception for failures to add, while offer returns a boolean to indicate success. Returning a boolean isn't an option, since the polled element will need to be returned. So for naming consistency, an exception approach would better use add in the method name.
Describe alternatives you've considered
See above. Call poll() and then call either offer() or add().
Implement the Copyable interface in the binary heap classes to enable easily copying a binary heap.
Add a MergeablePriorityQueueDouble interface as a sub-interface of PriorityQueueDouble, which includes a merge method.
The configuration file for Sonatype Lift includes an unnecessary exclusion for the source code of the test cases. The default exclusions should cover that.
The current retainAll has a runtime of O(n + m + (n-m) lg n). The (n-m) lg n term comes from making (n-m) calls to remove(Object). We can eliminate that term with an alternative approach that instead rebuilds the heap with the elements we're keeping. This will be O(n+m).
Summary
Planned functionality in dependent libraries will need a priority queue with changeable priorities. Integrate my existing not yet open sourced implementation with the following variations:
Also provide an interface to provide a common interface. Might need 2 though ine for integer and one for double priorities. The interface would later enable easily introducing other implementations such as fibonacci heap.
Add a MergeablePriorityQueue interface as a sub-interface of PriorityQueue, which includes a merge method.
In the DisjointIntegerSetForest, implement the Copyable interface, as well as the equals and hashCode methods.
Implement the Collections and Queue interfaces in the BinaryHeap and BinaryHeapDouble classes. Consider having PriorityQueue interface extend the Queue interface.
The current retainAll has a runtime of O(n + m + (n-m) lg n). The (n-m) lg n term comes from making (n-m) calls to remove(Object). We can eliminate that term with an alternative approach that instead rebuilds the heap with the elements we're keeping. This will be O(n+m).
Add a method to the BinaryHeap class for merging heaps.
BinaryHeapDouble currently relies on default implementation of removeAll(Collection) which simply calls the remove(Object) method once for each element in the Collection. The runtime of this approach is O(m lg n) where the heap currently has n elements and you are removing m of them. This can be improved to O(n + m) for the case when there are many to remove by rebuilding the heap with only the elements that you want to keep. If a relatively small number are to be removed, the current behavior is still faster. Reimplement with the O(n + m) approach, with a comment related to the small number of removals case.
Update pom.xml to target Java 17. Also update GitHub Action workflows to Java 17 as well as the project readme.md. Check website for any mention of minimum Java version.
Check code comments for notes on changes related to Java 17.
Be sure to bump major version number.
Summary
README.md is currently blank. Add content to it.
Add a Fibonacci heap implementation of a priority queue, including one class that implements PriorityQueue with int-valued priorities, and one class that implements PriorityQueueDouble with double-valued priorities.
The jitpack-build workflow triggers an ahead of time build on jitpack for the preferred groupId of org.cicirello on pushes to main for snapshot builds. Currently curls the target directory. Curl the maven metadata file instead to improve consistency of this ahead of time build trick.
FibonacciHeap currently relies on default implementation of removeAll(Collection) which simply calls the remove(Object) method once for each element in the Collection. The amortized runtime of this approach is O(m lg n) where the heap currently has n elements and you are removing m of them. This can be improved to O(n + m) for the case when there are many to remove by rebuilding the heap with only the elements that you want to keep. If a relatively small number are to be removed, the current behavior is still faster. Reimplement with the O(n + m) approach, with a comment related to the small number of removals case.
The existing BinaryHeap class supports constant time containment checks which enables efficient priority changes and arbitrary removals. It accomplishes this by maintaining a hash table based index into the heap.
Additionally, the existing class limits use to distinct objects, related to hash table use.
Add a simpler binary heap class without the hash table based index. Some applications may not need containment checks, priority changes, and arbitrary removals. Provide alternative without the overhead associated with this. Also allow duplicates.
The createMinHeap(Collection) and createMaxHeap(Collection) methods of the BinaryHeap and BinaryHeapDouble classes have javadoc comments that indicate they create an empty heap. This is wrong.
Add a Fibonacci heap implementation of the IntPriorityQueue interface.
To minimize redundant code. refactor FibonacciHeap to extend SimpleFibonacciHeap.
Summary
An implementation of a partially filled array of primitive int values. Should have similar methods to Java's ArrayList class where possible but without using wrapper objects.
FibonacciHeapDouble currently relies on default implementation of removeAll(Collection) which simply calls the remove(Object) method once for each element in the Collection. The amortized runtime of this approach is O(m lg n) where the heap currently has n elements and you are removing m of them. This can be improved to O(n + m) for the case when there are many to remove by rebuilding the heap with only the elements that you want to keep. If a relatively small number are to be removed, the current behavior is still faster. Reimplement with the O(n + m) approach, with a comment related to the small number of removals case.
Add a DisjointSetForest same method for checking if two element in same set.
Add a method to the FibonacciHeapDouble class for merging heaps.
One of the steps of the deployment workflow triggers an ahead of time build on jitpack for the preferred groupId of org.cicirello for each release. Currently curls the target directory. Curl the maven metadata file instead to improve consistency of this ahead of time build trick.
The existing FibonacciHeap class supports constant time containment checks which enables efficient priority changes and arbitrary removals. It accomplishes this by maintaining a hash table based index into the heap.
Additionally, the existing class limits use to distinct objects, related to hash table use.
Add a simpler Fibonacci heap class without the hash table based index. Some applications may not need containment checks, priority changes, and arbitrary removals. Provide alternative without the overhead associated with this. Also allow duplicates.
The existing FibonacciHeapDouble class supports constant time containment checks which enables efficient priority changes and arbitrary removals. It accomplishes this by maintaining a hash table based index into the heap.
Additionally, the existing class limits use to distinct objects, related to hash table use.
Add a simpler Fibonacci heap class without the hash table based index. Some applications may not need containment checks, priority changes, and arbitrary removals. Provide alternative without the overhead associated with this. Also allow duplicates.
Is your feature request related to a problem? Please describe.
In multiple of my other libraries, there are methods that take an array as a parameter to hold the result. For example, RandomSampler of the rho-mu library has various sample methods that generate a random sample. In cases like this, the length of the array passed as parameter must be validated against required length, with a new one constructed if too short. Such is also the case in the SequenceSampler class of the jpt library. In both cases, helper methods were implemented for this.
Describe the solution you'd like
A utility class, perhaps called ArrayEnforcer with methods that do null checks and length checks of an array passed as parameter, either returning that array if sufficient length, or returning a new array of adequate length. Should include the following:
Describe alternatives you've considered
Currently, multiple libraries recreate this functionality as private helpers.
BinaryHeap currently relies on the default implementation of the addAll(Collection) method, which simply calls the add method repeatedly, for a worst case runtime of O(m lg (n+m)) where m elements are added to a heap that currently has n elements. This is fine for small m, but in the case where many elements are added at once, this can be improved to O(n + m) by inserting the m new elements arbitrarily into the end of the array and then rebuilding the heap.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.