Skip to content

Instantly share code, notes, and snippets.

@shathor
shathor / FuzzySubstringSearch.java
Last active May 20, 2023 03:32
Performs a fuzzy substring search to find and return a portion of a string that matches with another, considering a max. allowed distance between the two. It is a slightly modified Levenshtein distance. E.g. Looking for 'abcd' in 'xyzabydxyz' and a maximum distance of 1 will return 'abyd'. Useful when trying to fuzzy search in a sentence.
package ch.sgwerder.gist;
import org.junit.jupiter.api.Assertions; // only for testing, see below
import org.junit.jupiter.api.Test; // only for testing, see below
import java.util.stream.IntStream;
/**
* Copyright (C) 2017 Simon Gwerder.
* <p/>
@shathor
shathor / EjectingIntQueue.java
Last active September 21, 2019 23:13
Sliding window view on a stream / sequence of int data. A non-blocking circular queue which automatically evicts elements from the head of the queue when attempting to add new elements into the array and it is full. Provides element insertion and removal at opposite ends (like a queue) and access to random elements in the container (like an array).
package ch.sgwerder.gist;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.RandomAccess;
/**
* Copyright (C) 2015 Simon Gwerder.
* <p/>
@shathor
shathor / EjectingQueue.java
Last active October 14, 2021 19:26
Sliding window view on a stream / sequence of data. A non-blocking circular queue which automatically evicts elements from the head of the queue when attempting to add new elements into the array and it is full. Provides element insertion and removal at opposite ends (like a queue) and access to random elements in the container (like an array).
package ch.sgwerder.gist;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.RandomAccess;
/**
* Copyright (C) 2015 Simon Gwerder.