GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mintern-java/primitive: Utility methods for Java's primitive types

BranchesTags
Open more actions menu

Latest commit

 

History

39 Commits
39 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

Repository files navigation

Java Primitive

Provides utility methods for functionality related to primitive types. This currently includes sorting and searching based on custom comparators.

To include the library in your project (Java 8+ supported), add the following to your POM:

<project>
...
    <dependencies>
        ...
        <dependency>
            <groupId>net.mintern</groupId>
            <artifactId>primitive</artifactId>
            <version>2.0</version>
        </dependency>
        ...
    </dependencies>
...
</project>
  • Sort arrays using primitive comparators
  • Binary search using primitive comparators
  • Sample usage
  • Contributing
    • Building
    • Where are all the source files?
    • Deploy new release
  • Related projects

Sort arrays using primitive comparators

The Primitive.sort(...) methods allow primitive arrays to be sorted using custom comparators (defined in net.mintern.primitive.comparators). This library provides both stable and unstable sorting algorithms. When the stable algorithm is used, it keeps two values in the same relative position when the comparator returns 0 for those two values.

The stable algorithm is based on TimSort, the sorting algorithm originally developed for use in Python. The implementation in this library is a shameless copy-paste-edit of the JDK 8 version of Joshua Bloch's java.util.TimSort implementation.

The unstable algorithm is based on Java's default primitives Arrays.sort implementation, a Dual-Pivot Quicksort. For some inputs, it may be up to twice as fast as stable sorting.

Binary search using primitive comparators

After sorting an array using a provided comparator, binary search can be performed using that same comparator. The implementation is another copy-paste-edit of the JDK 8 implementation.

Sample usage

int[] arr = ...;

// Sort by absolute values
Primitive.sort(arr, (i1, i2) -> Math.abs(i1) - Math.abs(i2));

// Sort in reverse order
IntComparator revCmp = (i1, i2) -> Integer.compare(i2, i1);
Primitive.sort(arr, revCmp);

// Binary search in reverse order (now that it's sorted)
int n = ...;
Primitive.binarySearch(arr, n, revCmp);

Contributing

I will happily accept Pull Requests. If you have any questions, ask away. Please keep changes to a minimum; do not make gratuitous style changes.

Building

In the root directory, run mvn install. That will build everything.

Where are all the source files?

For this project, I used an ancient-but-solid (by modern standards) template language called FreeMarker to provide templates that generate the source. A handy FreeMarker PreProcessor (FMPP)—in conjunction with an FMPP Maven plugin that I came across on Stack Overflow—turns those templates into the Java source files.

The template configuration and source is in src/main/fmpp.

Deploy new release

mvn clean deploy -P release

Related projects

All of my Java libraries are available in the mintern-java organization.

About

Utility methods for Java's primitive types

Resources

Readme
License
Activity
Custom properties

Stars

28 stars

Watchers

5 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.