All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.debatty.spark.knngraphs.builder.LSHSuperBit Maven / Gradle / Ivy

There is a newer version: 0.15
Show newest version
package info.debatty.spark.knngraphs.builder;

import info.debatty.java.graphs.Node;
import java.util.ArrayList;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.function.PairFlatMapFunction;
import scala.Tuple2;

/**
 *
 * @author tibo
 */
abstract class LSHSuperBit extends AbstractPartitioningBuilder {
    
    info.debatty.java.lsh.LSHSuperBit lsh;
    protected int dim;
    
    public void setDim(int dim) {
        this.dim = dim;
    }

    @Override
    protected JavaPairRDD> _binNodes(JavaRDD> nodes)  throws Exception {
        lsh = new info.debatty.java.lsh.LSHSuperBit(stages, buckets, this.dim);
        
        
        return nodes.flatMapToPair(
                new PairFlatMapFunction, Integer, Node>() {
            
            public Iterable>> call(Node n) throws Exception {
                ArrayList>> r = new ArrayList>>();
                int[] hash = hash(n.value);
                for (int v : hash) {
                    r.add(new Tuple2>(v, n));
                }
                
                return r;
            }
        });
    }

    abstract int[] hash(T node_value);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy