Skip to content

Instantly share code, notes, and snippets.

@lowasser
lowasser / Foo.java
Created March 7, 2012 16:17
Maps and mutable keys
import java.util.HashMap;
import java.util.Map;
public class Foo {
static class Mutable {
int value;
Mutable(int value) {
this.value = value;
}
package com.google.common.collect;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
import java.util.Random;
public class NullCheck extends SimpleBenchmark {
Object[] array = new Object[0x10000];
@lowasser
lowasser / FunctionBenchmark.java
Created April 10, 2012 21:47
Benchmark for Funcito-generated functions.
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.funcito.Funcito;
@lowasser
lowasser / Test.java
Created August 1, 2012 19:26 — forked from anonymous/Test.java
HashTable as array of Linked Lists
class Node {
public int data;
public Node next;
public Node(int data, Node next) {
this.data = data; this.next = next;
}
}
class LongIntParallelHashMultimap {
Node[] l ;
class Test {
public static void main(String[] args) {
List<Integer> voterA = Arrays.asList(1,2,3,4,5);
List<Integer> voterB = Arrays.asList(1,2,3,4,5);
List<List<Integer>> votes = Arrays.asList(voterA, voterB);
System.out.println(
IntStream.range(0, votes.stream().mapToInt(List::size).max().getAsInt())
.mapToInt(i -> votes.stream().mapToInt(voter -> voter.get(i)).sum())
.collect(Collectors.toList()));