Skip to content

Instantly share code, notes, and snippets.

@jhorstmann
jhorstmann / TestConversions.java
Created October 28, 2016 20:02
Investigating memory usage of exchange rate conversions in moneta
import org.javamoney.moneta.Money;
import javax.money.MonetaryAmount;
import javax.money.convert.CurrencyConversion;
import javax.money.convert.MonetaryConversions;
import java.math.BigDecimal;
public class TestConversions {
public static void main(String[] args) throws InterruptedException {
@jhorstmann
jhorstmann / CartesianProduct.java
Last active May 22, 2018 21:02
Lazy Cartesian Product
package org.zuchini.examples.parallel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Spliterator;
// https://en.wikipedia.org/wiki/Double_dabble
public class DoubleDabble {
static int bcd(int value, int bits) {
int res = value << (16 - bits);
res <<= 3;
for (int i = 3; i < bits; i++) {
// find bcd digits > 4 and incremented them 3
// either bit 4 is set or bit 3 and at least on of bits 2 or 1 is set
// bit 1 in mask ist set if digit > 4
// to get the add operand or the mask with mask<<1
import java.io.*;
public class ReadLineBenchmark {
long volume = 0;
static class StringSlice implements CharSequence {
private final String str;
private final int idx;
private final int end;
package net.jhorstmann.queryengine
import org.junit.jupiter.api.Test
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Opcodes
import org.objectweb.asm.util.CheckClassAdapter
import java.io.FileOutputStream
import java.util.function.IntSupplier
import java.util.function.Supplier