Coder Social home page Coder Social logo

blackbaroness / fastutil-extender Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 260 KB

Library built under the fastutil which offers various methods for creating collections, which makes your code more efficient and faster

License: MIT License

Kotlin 2.47% Java 97.53%
java fastutil collections boilerplate optimization library primitive-collections

fastutil-extender's Introduction

Extension built under a fastutil library

Don't waste your time by specifying a load factor, creating convertation algorithms, collectors and other boring boilerplate things!

You need Java 8+ to use this.

Import to your project

Maven:

<dependency>
    <groupId>io.github.blackbaroness</groupId>
    <artifactId>fastutil-extender-common</artifactId>
    <version>1.2.0</version>
</dependency>

Gradle (Groovy SDK):

implementation 'io.github.blackbaroness:fastutil-extender-common:1.2.0'

Gradle (Kotlin SDK):

implementation("io.github.blackbaroness:fastutil-extender-common:1.2.0")

Features

1. Fastest load factors by default

While doing benchmarks, I realized that load factor 0.25 significantly speeds up hash-based collections, wasting just a bit of RAM. If you don't feel sorry for the extra 1MB of RAM, this library is for you.

2. Cool stateless factories for lists and sets

IntListFactory factory = FastList.ints;

// default
factory.create();

// with size
factory.create(10);

// of array of boxed types
factory.of(1, 2, 3);

// of array of primitive types
factory.ofArray(1, 2, 3);

// convert from another type
List<String> stringList = FastList.objects.of("1", "2", "3");
factory.convert(stringList, Integer::parseInt);

// make unmodifiable of synchronized
factory.unmodifiable(factory.create());
factory.synchronize(factory.create());

// use collectors for streams
IntStream.of(1, 2, 3).boxed().collect(factory.collector());
IntStream.of(1, 2, 3).boxed().collect(factory.unmodifiableCollector());

// or use super cool builders
IntList list = factory.builder()
    .size(100)
    .content(1, 2, 3)
    .threadsafe()
    .unmodifiable()
    .build();

3. Simple map factory

// default
FastMap.newMap();

// with size
FastMap.newByte2ShortSortedMap(30);

// of pairs (currently only for objects)
FastMap.newMap(
    Pair.of("s1", "s2")
);

// make unmodifiable or synchronized
FastMap.unmodifiable(FastMap.newInt2IntMap());
FastMap.synchronize(FastMap.newByte2FloatMap());

4. Guice support

You must add fastutil-extender-guice module for this.

Combine your modules with fastutil-extender:

Module module = Modules.combine(/* your modules */, new FastUtilExtenderFactoriesModule());

Now factories will be injected into your classes:

class Example {
    
    private final List<Object> list;

    @Inject
    public Example(BooleanListFactory booleanListFactory) {
        this.list = booleanListFactory.builder().threadsafe().build();
    }
}

fastutil-extender's People

Contributors

blackbaroness avatar dependabot[bot] avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.