-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Bifurcan library in benchmarks
- Loading branch information
1 parent
a5188d9
commit c58a40d
Showing
7 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/jmh/java/io/usethesource/capsule/jmh/impl/persistent/bifurcan/BifurcanMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/jmh/java/io/usethesource/capsule/jmh/impl/persistent/bifurcan/BifurcanMapBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
src/jmh/java/io/usethesource/capsule/jmh/impl/persistent/bifurcan/BifurcanSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/jmh/java/io/usethesource/capsule/jmh/impl/persistent/bifurcan/BifurcanSetBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/jmh/java/io/usethesource/capsule/jmh/impl/persistent/bifurcan/BifurcanValueFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
} |