Commit 6d9b8b2c authored by David Novak's avatar David Novak
Browse files

Merge branch 'version3' into 'master'

Version3

See merge request !1
parents 464983e3 27eb6909
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
/target/
/test/
pppcodes.bin
*.iml
.idea
nbactions.xml

gplize.sh

0 → 100755
+47 −0
Original line number Diff line number Diff line
#!/bin/bash

find $* -not -path '*/.svn' -not -path '*/.git' -not -name 'package-info.java' -name '*.java' | while read f;do
	cat >$f.tmp <<EOF
/*
 *  This file is part of PPP-Codes library: https://bitbucket.org/disalab/ppp-codes
 *
 *  PPP-Codes library is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  PPP-Codes library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with PPP-Codes library.  If not, see <http://www.gnu.org/licenses/>.
 */
EOF
	perl -e '
		my $x = 0;
		my $a = 0;
		my $as = "";
		while (<>) {
			$x = 1 if (/package /);
			#if (/(^.*\@author) / || /^ \* Created by/) {
			#$a = $a + 1;
			#	$as = $as . $_;
			#} else {
			#	if ($a > 0) {
			#		if ($a < 3) {
			#			print " * \@author David Novak, Masaryk University, Brno, Czech Republic, david.novak\@fi.muni.cz\n";
			#		} else {
			#			print $as;
			#		}
			#		$a = 0;
			#	}
				print if ($x);
			#}
		}
		die "No package line found in $ARGV" unless ($x);
	' $f >> $f.tmp &&\
	mv -f $f.tmp $f
done

nbactions.xml

deleted100644 → 0
+0 −19
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<actions>
        <action>
            <actionName>build-with-dependencies</actionName>
            <reactor>also-make</reactor>
            <goals>
                <goal>install</goal>
                <goal>dependency:copy-dependencies</goal>
            </goals>
        </action>
        <action>
            <actionName>CUSTOM-build and copy dependencies</actionName>
            <displayName>build and copy dependencies</displayName>
            <goals>
                <goal>install</goal>
                <goal>dependency:copy-dependencies</goal>
            </goals>
        </action>
    </actions>
+10 −27
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@

    <groupId>mindex</groupId>
    <artifactId>ppp-codes</artifactId>
    <version>1.4.2-DEVEL</version>
    <version>3.0.1-DEVEL</version>
    <packaging>jar</packaging>

    <name>ppp-codes</name>
@@ -16,32 +16,18 @@
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
<!--            <plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>/home/xnovak8/work/simcloud/jars</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <includeScope>compile</includeScope>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy</id>
                        <phase>install</phase>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
@@ -54,14 +40,11 @@
                                    <type>${project.packaging}</type>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>/home/xnovak8/work/simcloud/jars</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <outputDirectory>/Users/david/ximilar-deploy/version3/common/jars</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>     -->
            </plugin>
        </plugins>
    </build>
    <properties>
@@ -102,7 +85,7 @@
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>mindex</artifactId>
            <version>(2.8.0,)</version>
            <version>3.0.0-DEVEL</version>
        </dependency>
    </dependencies>
    <description>PPP-Codes index and search algorithm for approximate metric-based search. 
+118 −83
Original line number Diff line number Diff line
/*
 *  This file is part of PPP-Codes library: http://disa.fi.muni.cz/results/software/ppp-codes/
 *  This file is part of PPP-Codes library: https://bitbucket.org/disalab/ppp-codes
 *
 *  PPP-Codes library is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
@@ -16,46 +16,46 @@
 */
package pppcodes;

import java.util.Arrays;
import pppcodes.index.PPPCodeInternalCell;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import messif.algorithms.AlgorithmMethodException;
import messif.algorithms.NavigationProcessor;
import messif.buckets.BucketDispatcher;
import messif.objects.LocalAbstractObject;
import messif.operations.AbstractOperation;
import messif.operations.data.BulkInsertOperation;
import messif.operations.data.DataManipulationOperation;
import messif.operations.data.DeleteOperation;
import messif.operations.data.InsertOperation;
import mindex.MIndexObjectInitilizer;
import messif.algorithm.AlgorithmMethodException;
import messif.data.DataObject;
import messif.distance.DistanceFunc;
import mindex.MIndexProperties;
import mindex.MetricIndex;
import mindex.VoronoiTreeIndex;
import mindex.navigation.VoronoiInternalCell;
import mindex.processors.DataManipulationNavigationProcessor;
import pppcodes.ids.IDString2IntConverter;
import pppcodes.index.PPPCodeInternalCell;
import pppcodes.index.PPPCodeObject;
import pppcodes.index.PPPCodeReadWriter;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.logging.Logger;
import java.util.stream.Collectors;


/**
 * The full configuration and some functionality of one PPP-Code tree index. It extends the M-Index because
 * The full config and some functionality of one PPP-Code tree index. It extends the M-Index because
 *  it shares many common features and code.
 * 
 * @author David Novak, Masaryk University, Brno, Czech Republic, novak.david@gmail.com
 */
public class PPPCodeIndex extends MetricIndex {
public class PPPCodeIndex extends VoronoiTreeIndex<PPPCodeObject> {
    
    /** Class serial ID for serialization */
    private static final long serialVersionUID = 112300L;
    private static final long serialVersionUID = 112301L;
    
    /** PPP Code serializer - it can be null */
    protected transient PPPCodeReadWriter pppCodeSerializer;

    //************************************   Getters ************************//
    /** Random generator - it can be null. */
    //protected transient Random random;

    /** The string-integer locator transformer used when the standard data object is transformed to {@link PPPCodeObject}. */
    protected IDString2IntConverter idConverter;


    // region ************************************   Getters
    
    /**
     * Returns a serializer for PPP Codes.
@@ -93,30 +93,44 @@ public class PPPCodeIndex extends MetricIndex {
        return false;
    }

    @Override
    public boolean isCheckDuplicateDC() {
        return false;
    }

    /**
     * TODO: read this either from config and/or from the LocatorID convertor
     * TODO: read this either from config and/or from the LocatorID converter
     * @return 
     */
    public long getMaxObjectNumber() {        
        return Integer.MAX_VALUE;
//        return configuration.getLongProperty(MIndexProperty.MAX_OBJECT_NUMBER);
//        return config.getLongProperty(MIndexProperty.MAX_OBJECT_NUMBER);
    }

//    public Random getRandom() {
//        if (random == null) {
//            random = new Random(System.currentTimeMillis());
//        }
//        return random;
//    }
    // endregion


    // **************************************    Initialization   ************************************* //
    // region **************************************    Initialization

    /**
     * Creates new instance of M-Index having a file name of M-Index properties.
     * @param origConfiguration created properties specifying M-Index configuration
     * @param origConfiguration created properties specifying M-Index config
     * @param prefix prefix of the properties (e.g. "mindex.") for this PPP-Code single index
     * @throws java.lang.InstantiationException
     */
    public PPPCodeIndex(Properties origConfiguration, String prefix) throws InstantiationException, AlgorithmMethodException {
        this( new MIndexProperties(origConfiguration, prefix));
    public PPPCodeIndex(Properties origConfiguration, String prefix, DistanceFunc<DataObject> distanceFunc, IDString2IntConverter idConverter) throws InstantiationException, AlgorithmMethodException {
        this( new MIndexProperties(origConfiguration, prefix), distanceFunc, idConverter);
    }
    
    protected PPPCodeIndex(MIndexProperties config) throws InstantiationException, AlgorithmMethodException {
        super(config);
    protected PPPCodeIndex(MIndexProperties config, DistanceFunc<DataObject> distanceFunc, IDString2IntConverter idConverter) throws InstantiationException, AlgorithmMethodException {
        super(config, distanceFunc);
        this.idConverter = idConverter;
    }

    @Override
@@ -124,14 +138,14 @@ public class PPPCodeIndex extends MetricIndex {
        return new PPPCodeInternalCell(this, null, new short[0]) ;
    }

    @Override
    protected MIndexObjectInitilizer initPPCalculator(MIndexProperties config) throws InstantiationException {
        return new PPPCodeInitializer(config);
    }

    @Override
    protected BucketDispatcher initBucketDispatcher(MIndexProperties config) throws InstantiationException {
        return null;
    /**
     * Sets a new locator converter for this PPP-Code algorithm. Use this method only if you very
     *  well know, what you're doing so that the serialized data is still compatible with the new
     *  converter.
     * @param idConverter new converter from string locators to the integer ones.
     */
    public final void setIDConverter(IDString2IntConverter idConverter) {
        this.idConverter = idConverter;
    }

    @Override
@@ -140,6 +154,36 @@ public class PPPCodeIndex extends MetricIndex {
        // NEVER PUT CONSOLIDATE DATA IN FINALIZE, BECAUSE IT WOULD BE CALLED AFTER THE SERIALIZATION
        super.finalize();
    }
    // endregion


    // region  ************************        Implementation of abstract methods that work with the data objects

    @Override
    public PPPCodeObject initObject(DataObject object) {
        return new PPPCodeObject(idConverter.getIntLocator(object.getID()), ppCalculator.getPPP(object));
    }

    @Override
    public Collection<PPPCodeObject> initObjects(DataObject[] objects) {
        return Arrays.stream(objects).map(this::initObject).collect(Collectors.toList());
    }

    @Override
    public short[] getPPP(PPPCodeObject object) {
        return object.getPppForReading();
    }

    @Override
    public DataObject getDataObject(PPPCodeObject indexObject) {
        if (indexObject.getLocatorCount() != 1) {
            Logger.getLogger(PPPCodeIndex.class.getName()).warning("creating a " + DataObject.class.getSimpleName() + " from PPPCode object with more (or less) than one object ID: " + Arrays.toString(indexObject.getLocators()));
        }
        return DataObject.objectWithID(idConverter.getStringLocator(indexObject.getLocators()[0]));
    }
    // endregion



    // *********************  Methods taking care about the storage and dynamic levels of M-Index  ********************** //
        
@@ -147,7 +191,6 @@ public class PPPCodeIndex extends MetricIndex {
     * Return the number of objects stored by this M-Index.
     * @return the number of objects stored by this M-Index.
     */
    @Override
    public int getObjectCount() {
        return voronoiCellTree.getObjectCount();
    }
@@ -166,44 +209,36 @@ public class PPPCodeIndex extends MetricIndex {
        ((PPPCodeInternalCell) voronoiCellTree).consolidateData(new byte[1024 * 1024]);
    }
    
    @Override
    public short [] readPPP(LocalAbstractObject object) {
        if (object instanceof PPPCodeObject) {
            return ((PPPCodeObject) object).getPppForReading();
        }
        return super.readPPP(object);
    }
    
    
    // *******************************   Methods processing operations *************************************** //
    
    /** Pre-created list of supported operations. */
    private final static List<Class<? extends AbstractOperation>> supportedOperations = 
            Collections.unmodifiableList((List) Arrays.asList(BulkInsertOperation.class, InsertOperation.class, DeleteOperation.class));
    
    @Override
    public List<Class<? extends AbstractOperation>> getSupportedOpList() {
        return PPPCodeIndex.supportedOperations;
    }

    /**
     * Method that creates specific implementation of NavigationProcessor for  each type of operation - a single
     *  PPP-Code index can process only the insert/delete/update operations.
     * @param operation to be processed
     * @return a specific implementation of NavigationProcessor
     */
    @Override
    public NavigationProcessor<? extends AbstractOperation> getNavigationProcessor(AbstractOperation operation) {
        try {
            // For InsertOperation, BulkInsertOperation and DeleteOperation
            if (operation instanceof DataManipulationOperation) {
                return DataManipulationNavigationProcessor.getInstance(operation, this);
            }
        } catch (AlgorithmMethodException e) {
            throw new IllegalStateException(e);
        }
        throw new UnsupportedOperationException("PPP-Code single algorithm does not support processing of operation " + operation.getClass());
    }
//
//    /** Pre-created list of supported operations. */
//    private final static List<Class<? extends AbstractOperation>> supportedOperations =
//            Collections.unmodifiableList((List) Arrays.asList(BulkInsertOperation.class, InsertOperation.class, DeleteOperation.class));
//
//    @Override
//    public List<Class<? extends AbstractOperation>> getSupportedOpList() {
//        return PPPCodeIndex.supportedOperations;
//    }
//
//    /**
//     * Method that creates specific implementation of NavigationProcessor for  each type of operation - a single
//     *  PPP-Code index can process only the insert/delete/update operations.
//     * @param operation to be processed
//     * @return a specific implementation of NavigationProcessor
//     */
//    @Override
//    public NavigationProcessor<? extends AbstractOperation> getNavigationProcessor(AbstractOperation operation) {
//        try {
//            // For InsertOperation, BulkInsertOperation and DeleteOperation
//            if (operation instanceof DataManipulationOperation) {
//                return DataManipulationNavigationProcessor.getInstance(operation, this);
//            }
//        } catch (AlgorithmMethodException e) {
//            throw new IllegalStateException(e);
//        }
//        throw new UnsupportedOperationException("PPP-Code single algorithm does not support processing of operation " + operation.getClass());
//    }

    
    // *********************************************   Auxilionary methods   ********************************* //
Loading