descriptionJava memoization library
homepage URLhttps://github.com/sebhoss/memoization.java
repository URLhttps://github.com/sebhoss/memoization.java.git
ownerrepoorcz@shoss.de
last changeThu, 8 Feb 2024 01:42:51 +0000 (8 02:42 +0100)
last refreshThu, 21 Nov 2024 07:41:31 +0000 (21 08:41 +0100)
content tags
add:
README.md

memoization.java Chat

Java memoization library - trade space for time

Features

Usage

Memoize any of the supported types by using the static factory methods supplied by:

Default cache with default cache keys

wtf.metio.memoization.jdk.Memoize;
wtf.metio.memoization.jool.MemoizeJool;
wtf.metio.memoization.lambda.MemoizeLambda;
wtf.metio.memoization.rxjava.MemoizeRx;

Function<INPUT, OUTPUT> function         = ...;
Function<INPUT, OUTPUT> memoizedFunction = Memoize.function(function);

Supplier<OUTPUT> supplier                = ...;
Supplier<OUTPUT> memoizedSupplier        = MemoizeRx.supplier(supplier);

Function3<T1, T2, T3, OUTPUT> function         = ...;
Function3<T1, T2, T3, OUTPUT> memoizedFunction = MemoizeJool.function3(function);

Fn4<T1, T2, T3, T4, OUTPUT> function         = ...;
Fn4<T1, T2, T3, T4, OUTPUT> memoizedFunction = MemoizeLambda.fn4(function);

Default cache with custom cache keys

wtf.metio.memoization.jdk.Memoize;
wtf.metio.memoization.jool.MemoizeJool;
wtf.metio.memoization.lambda.MemoizeLambda;
wtf.metio.memoization.rxjava.MemoizeRx;

Function<INPUT, OUTPUT> function         = ...;
Function<INPUT, KEY> keyFunction         = ...;
Function<INPUT, OUTPUT> memoizedFunction = Memoize.function(function, keyFunction);

Supplier<OUTPUT> supplier                = ...;
Supplier<KEY> keySupplier                = ...;
Supplier<OUTPUT> memoizedSupplier        = MemoizeRx.supplier(supplier, keySupplier);

Function3<T1, T2, T3, OUTPUT> function         = ...;
Function3<T1, T2, T3, KEY> keyFunction         = ...;
Function3<T1, T2, T3, OUTPUT> memoizedFunction = MemoizeJool.function3(function, keyFunction);

Fn4<T1, T2, T3, T4, OUTPUT> function         = ...;
Fn4<T1, T2, T3, T4, KEY> keyFunction         = ...;
Fn4<T1, T2, T3, T4, OUTPUT> memoizedFunction = MemoizeLambda.fn4(function, keyFunction);

Custom cache with default cache keys

wtf.metio.memoization.jdk.Memoize;
wtf.metio.memoization.jool.MemoizeJool;
wtf.metio.memoization.lambda.MemoizeLambda;
wtf.metio.memoization.rxjava.MemoizeRx;

// memoize in cache2k cache
Function<INPUT, OUTPUT> function         = ...;
Cache<INPUT, OUTPUT> cache               = ...; // org.cache2k.Cache
Function<INPUT, OUTPUT> memoizedFunction = Memoize.function(function, cache.asMap());

// memoize in Caffeine cache
Supplier<OUTPUT> supplier                = ...;
Cache<Integer, OUTPUT> cache             = ...; // com.github.benmanes.caffeine.cache.Cache
Supplier<OUTPUT> memoizedSupplier        = MemoizeRx.supplier(supplier, cache.asMap());

// memoize in Guava cache
Function3<T1, T2, T3, OUTPUT> function         = ...;
Cache<Integer, OUTPUT> cache                   = ...; // com.google.common.cache.Cache
Function3<T1, T2, T3, OUTPUT> memoizedFunction = MemoizeJool.function3(function, cache.asMap());

// memoize in ConcurrentMap
Fn4<T1, T2, T3, T4, OUTPUT> function         = ...;
Map<Integer, OUTPUT> cache                   = ...;
Fn4<T1, T2, T3, T4, OUTPUT> memoizedFunction = MemoizeLambda.fn4(function, cache);

Custom cache with custom cache keys

wtf.metio.memoization.jdk.Memoize;
wtf.metio.memoization.jool.MemoizeJool;
wtf.metio.memoization.lambda.MemoizeLambda;
wtf.metio.memoization.rxjava.MemoizeRx;

// memoize in cache2k cache
Function<INPUT, OUTPUT> function         = ...;
Function<INPUT, KEY> keyFunction         = ...;
Cache<KEY, OUTPUT> cache                 = ...; // org.cache2k.Cache
Function<INPUT, OUTPUT> memoizedFunction = Memoize.function(function, keyFunction, cache.asMap());

// memoize in Caffeine cache
Supplier<OUTPUT> supplier                = ...;
Supplier<KEY> keySupplier                = ...;
Cache<KEY, OUTPUT> cache                 = ...; // com.github.benmanes.caffeine.cache.Cache
Supplier<OUTPUT> memoizedSupplier        = MemoizeRx.supplier(supplier, keySupplier, cache.asMap());

// memoize in Guava cache
Function3<T1, T2, T3, OUTPUT> function         = ...;
Function3<T1, T2, T3, KEY> keyFunction         = ...;
Cache<KEY, OUTPUT> cache                       = ...; // com.google.common.cache.Cache
Function3<T1, T2, T3, OUTPUT> memoizedFunction = MemoizeJool.function3(function, keyFunction, cache.asMap());

// memoize in ConcurrentMap
Fn4<T1, T2, T3, T4, OUTPUT> function         = ...;
Fn4<T1, T2, T3, T4, KEY> keyFunction         = ...;
Map<KEY, OUTPUT> cache                       = ...;
Fn4<T1, T2, T3, T4, OUTPUT> memoizedFunction = MemoizeLambda.fn4(function, keyFunction, cache);

Note that the static factory methods do accept any Map, however they copy the entries in the map to a new ConcurrentHashMap in case the provided Map is not a ConcurrentMap. This is done in order to ensure atomic computeIfAbsent behavior.

Integration

In order to use this project, declare the following dependencies in your project:

<dependencies>
    <!-- support for JDK interfaces -->
    <dependency>
        <groupId>wtf.metio.memoization</groupId>
        <artifactId>memoization-jdk</artifactId>
        <version>${version.memoization}</version>
    </dependency>
    <!-- support for JDK interfaces -->

    <!-- support for jOOL interfaces -->
    <dependency>
        <groupId>wtf.metio.memoization</groupId>
        <artifactId>memoization-jool</artifactId>
        <version>${version.memoization}</version>
    </dependency>
    <!-- support for jOOL interfaces -->

    <!-- support for lambda interfaces -->
    <dependency>
        <groupId>wtf.metio.memoization</groupId>
        <artifactId>memoization-lambda</artifactId>
        <version>${version.memoization}</version>
    </dependency>
    <!-- support for lambda interfaces -->

    <!-- support for RxJava interfaces -->
    <dependency>
        <groupId>wtf.metio.memoization</groupId>
        <artifactId>memoization-rxjava</artifactId>
        <version>${version.memoization}</version>
    </dependency>
    <!-- support for RxJava interfaces -->
</dependencies>

Replace ${version.memoization} with the latest release.

Alternatives

License

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
shortlog
2024-02-08 sebhossUpdate parent to latest versionmain
2024-01-08 sebhossUpdate parent to latest version2024.1.8
2023-12-14 Sebastian Hoßupdate workflows (#206)
2023-12-08 sebhossUpdate parent to latest version2023.12.12
2023-11-08 sebhossUpdate parent to latest version2023.11.14
2023-10-08 sebhossUpdate parent to latest version2023.10.10
2023-09-08 sebhossUpdate parent to latest version2023.9.12
2023-08-08 sebhossUpdate parent to latest version2023.8.8
2023-07-08 sebhossUpdate parent to latest version2023.7.11
2023-06-08 sebhossUpdate parent to latest version2023.6.13
2023-05-08 sebhossUpdate parent to latest version2023.5.9
2023-04-08 sebhossUpdate parent to latest version2023.4.11
2023-03-08 sebhossUpdate parent to latest version2023.3.14
2023-02-08 sebhossUpdate parent to latest version2023.2.14
2023-01-08 Sebastian Hoßfix jspecify package name2023.1.10
2023-01-08 sebhossUpdate parent to latest version
...
tags
10 months ago 2024.1.8
11 months ago 2023.12.12
12 months ago 2023.11.14
13 months ago 2023.10.10
14 months ago 2023.9.12
15 months ago 2023.8.8
16 months ago 2023.7.11
17 months ago 2023.6.13
18 months ago 2023.5.9
19 months ago 2023.4.11
20 months ago 2023.3.14
21 months ago 2023.2.14
22 months ago 2023.1.10
23 months ago 2022.12.13
23 months ago 2022.12.6
2 years ago 2022.11.22
...
heads
9 months ago main