Skip to content

Commit

Permalink
Support Bifurcan library in benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
msteindorfer committed Oct 2, 2023
1 parent a5188d9 commit c58a40d
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {

/*** 3rd party Java libraries with persistent data structures ***/
jmh(group = "com.github.andrewoma.dexx", name = "collection", version = "0.7")
jmh(group = "io.lacuna", name = "bifurcan", version = "0.2.0-alpha6")
jmh(group = "io.vavr", name = "vavr", version = "0.10.4")
jmh(group = "org.organicdesign", name = "Paguro", version = "3.10.3")
jmh(group = "org.pcollections", name = "pcollections", version = "4.0.1")
Expand Down
7 changes: 7 additions & 0 deletions src/jmh/java/io/usethesource/capsule/jmh/BenchmarkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import io.usethesource.capsule.jmh.api.JmhValueFactory;
import io.usethesource.capsule.jmh.impl.immutable.guava.ImmutableGuavaValueFactory;
import io.usethesource.capsule.jmh.impl.persistent.bifurcan.BifurcanValueFactory;
import io.usethesource.capsule.jmh.impl.persistent.capsule.CapsuleValueFactory;
import io.usethesource.capsule.jmh.impl.persistent.clojure.ClojureValueFactory;
import io.usethesource.capsule.jmh.impl.persistent.dexx.DexxValueFactory;
Expand All @@ -23,6 +24,12 @@
public class BenchmarkUtils {

public enum ValueFactoryFactory {
VF_BIFURCAN {
@Override
public JmhValueFactory getInstance() {
return new BifurcanValueFactory();
}
},
VF_CLOJURE {
@Override
public JmhValueFactory getInstance() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.capsule.jmh.impl.persistent.bifurcan;

import io.lacuna.bifurcan.Map;
import io.usethesource.capsule.jmh.api.JmhMap;
import io.usethesource.capsule.jmh.api.JmhValue;

import java.util.Iterator;
import java.util.Map.Entry;

public final class BifurcanMap implements JmhMap {

private final Map<JmhValue, JmhValue> content;

BifurcanMap(Map<JmhValue, JmhValue> content) {
this.content = content;
}

@Override
public boolean isEmpty() {
return content.size() == 0;
}

@Override
public int size() {
return Math.toIntExact(content.size());
}

@Override
public JmhMap put(JmhValue key, JmhValue value) {
return new BifurcanMap((Map<JmhValue, JmhValue>) content.put(key, value));
}

@Override
public JmhMap removeKey(JmhValue key) {
return new BifurcanMap(content.remove(key));
}

@Override
public boolean containsKey(JmhValue key) {
return content.contains(key);
}

@Override
public boolean containsValue(JmhValue value) {
return content.stream().filter(entry -> entry.value().equals(value)).findAny().isEmpty();
}

@Override
public JmhValue get(JmhValue key) {
return content.get(key).get();
}

@Override
public int hashCode() {
return content.hashCode();
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (other == null) {
return false;
}

if (other instanceof BifurcanMap) {
BifurcanMap that = (BifurcanMap) other;

if (this.size() != that.size()) {
return false;
}

return content.equals(that.content);
}

return false;
}

@Override
public Object unwrap() {
return content;
}

@Override
public Iterator<JmhValue> iterator() {
return content.keys().iterator();
}

@Override
public Iterator<JmhValue> valueIterator() {
return content.values().iterator();
}

@Override
public Iterator<Entry<JmhValue, JmhValue>> entryIterator() {
return content.stream().map(entry -> java.util.Map.entry(entry.key(), entry.value())).iterator();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.capsule.jmh.impl.persistent.bifurcan;

import io.lacuna.bifurcan.Map;
import io.usethesource.capsule.jmh.api.JmhValue;
import io.usethesource.capsule.jmh.impl.AbstractMapBuilder;

final class BifurcanMapBuilder extends AbstractMapBuilder<JmhValue, Map<JmhValue, JmhValue>> {

BifurcanMapBuilder() {
super(Map.empty(), map -> (key, value) -> (Map<JmhValue, JmhValue>) map.put(key, value), BifurcanMap::new);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.capsule.jmh.impl.persistent.bifurcan;

import io.lacuna.bifurcan.Set;
import io.usethesource.capsule.jmh.api.JmhSet;
import io.usethesource.capsule.jmh.api.JmhValue;

import java.util.Iterator;

public final class BifurcanSet implements JmhSet {

private final Set<JmhValue> content;

public BifurcanSet(Set<JmhValue> content) {
this.content = content;
}

@Override
public boolean isEmpty() {
return content.size() == 0;
}

@Override
public JmhSet insert(JmhValue value) {
return new BifurcanSet(content.add(value));
}

@Override
public JmhSet delete(JmhValue value) {
return new BifurcanSet(content.remove(value));
}

@Override
public int size() {
return Math.toIntExact(content.size());
}

@Override
public boolean contains(JmhValue value) {
return content.contains(value);
}

@Override
public Iterator<JmhValue> iterator() {
return content.iterator();
}

@Override
public java.util.Set<JmhValue> asJavaSet() {
return content.toSet();
}

@Override
public int hashCode() {
return content.hashCode();
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (other == null) {
return false;
}

if (other instanceof BifurcanSet) {
BifurcanSet that = (BifurcanSet) other;

if (this.size() != that.size()) {
return false;
}

return content.equals(that.content);
}

return false;
}

@Override
public Object unwrap() {
return content;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.capsule.jmh.impl.persistent.bifurcan;

import io.lacuna.bifurcan.Set;
import io.usethesource.capsule.jmh.api.JmhValue;
import io.usethesource.capsule.jmh.impl.AbstractSetBuilder;

final class BifurcanSetBuilder extends AbstractSetBuilder<JmhValue, Set<JmhValue>> {

BifurcanSetBuilder() {
super(Set.empty(), set -> set::add, BifurcanSet::new);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) Michael Steindorfer <Centrum Wiskunde & Informatica> and Contributors.
* All rights reserved.
*
* This file is licensed under the BSD 2-Clause License, which accompanies this project
* and is available under https://opensource.org/licenses/BSD-2-Clause.
*/
package io.usethesource.capsule.jmh.impl.persistent.bifurcan;

import io.usethesource.capsule.jmh.api.JmhMap;
import io.usethesource.capsule.jmh.api.JmhSet;
import io.usethesource.capsule.jmh.api.JmhValueFactory;

public class BifurcanValueFactory implements JmhValueFactory {

@Override
public JmhSet.Builder setBuilder() {
return new BifurcanSetBuilder();
}

@Override
public JmhMap.Builder mapBuilder() {
return new BifurcanMapBuilder();
}

@Override
public String toString() {
return "VF_BIFURCAN";
}

}

0 comments on commit c58a40d

Please sign in to comment.