Skip to content

Instantly share code, notes, and snippets.

@ib84
ib84 / validationsShortened.scala
Last active December 16, 2015 11:09
validationsHOF&Underscores
def findX(name:String, keys: (HGSortIndex[K,V], K) => HGSearchResult[V], disc:(Ordering[K],K,K) => Boolean) :
(name, (index:S, dataSeq:Seq[(K,Seq[V])]) => Try
{
val allTrue = dataSeq.forall{ case (key, valueSeq) =>
{
val b :HGSearchResult[V]= keys(index, key)
val ordering = implicitly[Ordering[K]]
val c = dataSeq.filter( pair => disc(ordering, pair._1,
key)).map(_._1).toSet
b.forall(key => c.contains(key))
@ib84
ib84 / validationsBefore.scala
Last active December 16, 2015 10:39
Naive version of a series of tests (validations) for a test.
val validatations : Seq[(String, (S,Seq[(K,Seq[V])]) => Try[Boolean])]=
Seq(
("def findLT(key: K)", (index:S, dataSeq:Seq[(K,Seq[V])]) => Try
{
val allTrue = dataSeq.forall{ case (key, valueSeq) =>
{
val b = index.findLT(key)
val ordering = implicitly[Ordering[K]]
val c = dataSeq.filter( pair => ordering.lt(pair._1, key)).map(_._1).toSet
b.forall(key => c.contains(key))
@ib84
ib84 / hgdbJava.java
Created November 11, 2012 17:37
scala hypergraphdb demos
private static HGHandle linkLine(String [] stations, HyperGraph graph){
HGHandle[] stationHandles = new HGHandle[stations.length];
for (int i = 0; i < stations.length; i++){
stationHandles[i] = hg.assertAtom(graph, stations[i]);
}
return graph.add(new HGPlainLink(stationHandles));
}
public static void main(String[] args) {
HyperGraph graph = new HyperGraph("//home/ingvar/bin/sbt-KK/bje");
@ib84
ib84 / ScalaHGDBTransactions.scala
Created November 11, 2012 16:57
Scala HyperGraphDB-Transaction Utility methods + tests
object TestTransa {
import org.hypergraphdb.transaction.HGUserAbortException
import scala.runtime.NonLocalReturnControl
import org.hypergraphdb._
import HGQuery.hg
import java.lang.Throwable
import scala.annotation.tailrec
val graph:HyperGraph = new HyperGraph("/home/ingvar/bin/sbt-scala-hypergraphdb/bje")
@ib84
ib84 / Ordr.java
Created October 6, 2012 16:38
Ordering enums for index functions of Hazelcast storage implementation for HyperGraphDB
package org.hypergraphdb.storage.hazelstore;
public enum Ordr
{
LT, LTE, GT, GTE
}
@ib84
ib84 / BAWrapper.java
Created October 6, 2012 16:35
This Gist contains all classes of an alpha version of a HyperGraphDB storage implementation using Hazelcast
package org.hypergraphdb.storage;
import java.util.Arrays;
import java.io.Serializable;
public class BAWrapper implements Serializable{
private final byte[] data;
public BAWrapper(byte[] data)
{
@ib84
ib84 / HyperGraphDBScalaHacks.scala
Created July 24, 2012 08:12
Implicit conversions of HGHandle for improved usability of HyperGraphDB
object HGHandleHacks {
implicit def richHandle(handle: HGHandle)(implicit graph: HyperGraph) = new {
// DEREFERENCING
// dereference and type cast - may throw ClassCastException
def d[T](implicit graph: HyperGraph): T =
graph.get(handle).asInstanceOf[T]
@ib84
ib84 / gist:3002452
Created June 27, 2012 08:32
little hypergraphdb demo
package hgtest.storage
import org.hypergraphdb._
import collection.JavaConversions._
import org.hypergraphdb.HGQuery.hg
import org.hypergraphdb.query.AtomTypeCondition
import org.hypergraphdb.util.HGUtils
import storage.bje.BJEStorageImplementation
@ib84
ib84 / HGDBTextApp.scala
Created March 11, 2012 15:35
hypergraphDB Text Experiments
import test.JHGDB.TestCommons._
import org.hypergraphdb.HGQuery.hg
import scala.collection.JavaConversions._
import org.hypergraphdb.query.AtomTypeCondition
import test.Text.Word3
import java.util.ArrayList
import org.hypergraphdb.indexing.{ByTargetIndexer, ByPartIndexer}
import org.hypergraphdb.{HyperGraph, HGHandle, HGPlainLink}
object HGDBRecursiveTextTest {
@ib84
ib84 / Text.scala
Created February 29, 2012 11:36
recursive text type
package test
import scala.annotation.tailrec
import scala.collection.JavaConversions._
import scala.reflect.BeanProperty
sealed abstract class Text{
override def toString():String
//ToDo -- checkout Type bounds