Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks for v0.7.2 #29

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ target/
.classpath
.project
.settings/
.idea/
.idea/

.vscode/
.DS_Store
12 changes: 8 additions & 4 deletions make_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@

set -e

script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
cd "$script_dir"

git checkout master
# Make sure code builds
mvn package
# Make sure all files have licenses
mvn license:update-file-header
# Make sure code is formatted consistently
mvn com.spotify.fmt:fmt-maven-plugin:format
if [ -n "$(git status --porcelain)" ]; then
echo "Directory not clean"
exit 1
fi
# Make sure code builds
mvn package
# Generate Javadocs
mvn javadoc:javadoc -Prelease
git stash
Expand All @@ -36,4 +40,4 @@ git stash pop
#
# (This assumes you have a settings.xml file with the GPG passphrase and a
# Sonatype token.) Once the package is validated, you can publish it using the
# interface on <https://central.sonatype.org/>.
# interface on <https://central.sonatype.org/>.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>io.github.harvardpl</groupId>
<artifactId>AbcDatalog</artifactId>
<version>0.7.1</version>
<version>0.7.2</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public class ConcurrentFactIndexer<T extends Iterable<PositiveAtom>> implements
* @param addFunc an anonymous function that adds a fact to a container
* @param size an anonymous function that gets the number of items in the container
*/
public ConcurrentFactIndexer(Supplier<T> generator, BiConsumer<T, PositiveAtom> addFunc, Function<T, Integer> size) {
public ConcurrentFactIndexer(
Supplier<T> generator, BiConsumer<T, PositiveAtom> addFunc, Function<T, Integer> size) {
this(generator, addFunc, generator, size);
}

Expand All @@ -90,7 +91,10 @@ public ConcurrentFactIndexer(Supplier<T> generator, BiConsumer<T, PositiveAtom>
* @param size an anonymous function that gets the number of items in the container
*/
public ConcurrentFactIndexer(
Supplier<T> generator, BiConsumer<T, PositiveAtom> addFunc, Supplier<T> empty, Function<T, Integer> size) {
Supplier<T> generator,
BiConsumer<T, PositiveAtom> addFunc,
Supplier<T> empty,
Function<T, Integer> size) {
this.generator = generator;
this.addFunc = addFunc;
this.empty = empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ public void add(T e) {
h = this.head.get();
n = new Node(e, h);
} while (!this.head.compareAndSet(h, n));
// This is not updated atomically with the addition of the element and can thus only be considered a lower bound
// for the set size. However, consumers cannot tell the difference since there is no way to transactionally read
// the set size and traverse the set anyway.
// This is not updated atomically with the addition of the element and can
// thus only be considered a lower bound for the set size. However,
// consumers cannot tell the difference since there is no way to
// transactionally read the set size and traverse the set anyway.
size.incrementAndGet();
}

/**
* Returns the number of elements that have been added to the set.
*
* @return the size of the set
*/
public Integer size() { return size.get(); }
public Integer size() {
return size.get();
}

/**
* Returns the head of the linked-list that backs this bag, or null if there is no head.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ private FactIndexerFactory() {}
* @return the fact indexer
*/
public static ConcurrentFactIndexer<Set<PositiveAtom>> createConcurrentSetFactIndexer() {
return new ConcurrentFactIndexer<>(
Utilities::createConcurrentSet, Set::add, Set::size);
return new ConcurrentFactIndexer<>(Utilities::createConcurrentSet, Set::add, Set::size);
}

/**
Expand All @@ -60,7 +59,6 @@ public static ConcurrentFactIndexer<Set<PositiveAtom>> createConcurrentSetFactIn
* @return the fact indexer
*/
public static ConcurrentFactIndexer<Queue<PositiveAtom>> createConcurrentQueueFactIndexer() {
return new ConcurrentFactIndexer<>(
ConcurrentLinkedQueue::new, Queue::add, Queue::size);
return new ConcurrentFactIndexer<>(ConcurrentLinkedQueue::new, Queue::add, Queue::size);
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,86 @@
package edu.harvard.seas.pl.abcdatalog.util.datastructures;

/*-
* #%L
* AbcDatalog
* %%
* Copyright (C) 2016 - 2024 President and Fellows of Harvard College
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the President and Fellows of Harvard College nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

import edu.harvard.seas.pl.abcdatalog.ast.*;
import edu.harvard.seas.pl.abcdatalog.engine.AbstractTests;
import java.util.function.Supplier;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import java.util.function.Supplier;

@RunWith(Suite.class)
@Suite.SuiteClasses({
FactIndexerTest.SetTests.class,
FactIndexerTest.ConcurrentLinkedBagTests.class
})
public class FactIndexerTest {
public static class SetTests extends AbstractFactIndexerTests {
public SetTests() { super(FactIndexerFactory::createConcurrentSetFactIndexer); }
public static class SetTests extends AbstractFactIndexerTests {
public SetTests() {
super(FactIndexerFactory::createConcurrentSetFactIndexer);
}
}

public static class ConcurrentLinkedBagTests extends AbstractFactIndexerTests {
public ConcurrentLinkedBagTests() { super(FactIndexerFactory::createConcurrentQueueFactIndexer); }
public static class ConcurrentLinkedBagTests extends AbstractFactIndexerTests {
public ConcurrentLinkedBagTests() {
super(FactIndexerFactory::createConcurrentQueueFactIndexer);
}
}

public abstract static class AbstractFactIndexerTests extends AbstractTests {
private final Supplier<FactIndexer> factIndexerFactory;

public AbstractFactIndexerTests(Supplier<FactIndexer> factIndexerFactory) {
super(
() -> {
throw new Error("Tests do not use engine=");
});
this.factIndexerFactory = factIndexerFactory;
}

@Test
public void testSmallestFactSetIsReturnedFromFineIndex() {
FactIndexer indexer = factIndexerFactory.get();
indexer.addAll(parseFacts("f(a,x,b). f(b,x,b). f(c,x1,b). f(c,x2,b). f(c,x,d)."));

public static abstract class AbstractFactIndexerTests extends AbstractTests {
private final Supplier<FactIndexer> factIndexerFactory;

public AbstractFactIndexerTests(Supplier<FactIndexer> factIndexerFactory) {
super(() -> { throw new Error("Tests do not use engine="); });
this.factIndexerFactory = factIndexerFactory;
}

@Test
public void testSmallestFactSetIsReturnedFromFineIndex() {
FactIndexer indexer = factIndexerFactory.get();
indexer.addAll(parseFacts("f(a,x,b). f(b,x,b). f(c,x1,b). f(c,x2,b). f(c,x,d)."));

Iterable<PositiveAtom> result = indexer.indexInto(parseQuery("f(c,_,d)?"));
int size = 0;
for (PositiveAtom ignored : result) {
++size;
}
Assert.assertEquals(1, size);
}
Iterable<PositiveAtom> result = indexer.indexInto(parseQuery("f(c,_,d)?"));
int size = 0;
for (PositiveAtom ignored : result) {
++size;
}
Assert.assertEquals(1, size);
}
}
}
}
Loading