Commit 464983e3 authored by David Novak's avatar David Novak
Browse files

creating a special algorithm for the (deprecated) version with PPP-Tree leaves on the disk

parent 4d814d50
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@

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

    <name>ppp-codes</name>
+38 −0
Original line number Diff line number Diff line
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pppcodes.algorithms;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import messif.algorithms.Algorithm;

/**
 *
 * @author david
 * @deprecated it was never finished nor used
 */
@Deprecated
public class ConvertFileAlgorithm {
    
    public static void main (String [] args) {
        try {
            if (args.length < 2) {
                System.err.println("Usage: " + ConvertFileAlgorithm.class + " <input-ser-file> <output-ser-file>");
                return;
            }
            PPPCodeAlgorithm restoreFromFile = Algorithm.restoreFromFile(args[0], PPPCodeAlgorithm.class);
            for (PPPCodeSingleAlgorithm algorithm : restoreFromFile.algorithms) {
                PPPCodeSingleAlgorithmFile fileAlg = (PPPCodeSingleAlgorithmFile) algorithm;
                fileAlg.getmIndex();
                //new PPPCodeSingleAlgorithm(null, null);
                        
            }
        } catch (IOException | NullPointerException | ClassNotFoundException | ClassCastException ex) {
            Logger.getLogger(ConvertFileAlgorithm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
+3 −29
Original line number Diff line number Diff line
@@ -30,13 +30,10 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import messif.algorithms.Algorithm;
import messif.algorithms.NavigationProcessor;
import messif.algorithms.impl.MultipleOverlaysAlgorithm;
import messif.buckets.BucketStorageException;
import messif.buckets.storage.impl.DiskStorage;
import messif.operations.AbstractOperation;
import messif.operations.RankingSingleQueryOperation;
import messif.operations.data.BulkInsertOperation;
@@ -52,7 +49,6 @@ import pppcodes.PPPCodeIndex;
import pppcodes.PPPCodeIndexFile;
import pppcodes.ids.LocatorStringIntConvertor;
import pppcodes.index.PPPCodeInternalCell;
import pppcodes.index.persistent.PPPCodeLeafCellFile;
import pppcodes.processors.ApproxNavProcessorCandSet;
import pppcodes.processors.ApproxNavProcessorNorefine;
import pppcodes.processors.GetJoinCandidatesProcessor;
@@ -134,21 +130,15 @@ public class PPPCodeAlgorithm extends MultipleOverlaysAlgorithm {
   
    
    /**
     * Checks all the M-Index algorithms, if their dynamic cell tree was not modified and
     *  serializes the whole algorithm if it was changed. THis method is typically called
     *  periodically.
     * Checks if there was any update operation executed on this algorithm since the last serialization
     *  and call the serialization, if it there was any update.
     * @param serializationFile file to serialize the whole algorithm into
     * @throws IOException if the serialization failed
     */
    public void checkModifiedAndStore(String serializationFile) throws IOException {
        serializingLock.lock();
        try {
            boolean anyModified = false;
            for (MIndexAlgorithm mIndexAlgorithm : algorithms) {
                anyModified = anyModified || mIndexAlgorithm.getmIndex().isDynamicTreeModified();
            }
            if (anyModified) {
                // Store algorithm to file
            if (! isUpdateLogEmpty()) {
                this.storeToFile(serializationFile);
            }
        } finally {
@@ -172,22 +162,6 @@ public class PPPCodeAlgorithm extends MultipleOverlaysAlgorithm {
        }
    }        
    
    /**
     * If the PPP-Codes are configured using {@link PPPCodeIndexFile} then this method can
     *  set the storage to be used to store the leave node data. This method is efficient only
     *  for the first time - after that all leaves have links to a specific storage.
     * @param leafStorage disk storage to store the leaf data of all PPP-Code overlays
     */
    public void setLeafStorage(DiskStorage<PPPCodeLeafCellFile.PPPCodeLeafData> leafStorage) throws IllegalStateException, BucketStorageException {
        consolidateTreeData();
        for (PPPCodeSingleAlgorithm singleAlg : algorithms) {
            if (singleAlg.getmIndex() instanceof PPPCodeIndexFile) {
                ((PPPCodeIndexFile) singleAlg.getmIndex()).setLeafStorage(leafStorage);
            }
        }
        Logger.getLogger(PPPCodeAlgorithm.class.getName()).log(Level.INFO, "leaf disk storage set to: {0}", leafStorage.getFile());
    }

    /**
     * Sets a new locator convertor 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 
+99 −0
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/
 *
 *  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/>.
 */
package pppcodes.algorithms;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import messif.algorithms.Algorithm;
import messif.buckets.BucketStorageException;
import messif.buckets.storage.impl.DiskStorage;
import mindex.algorithms.MIndexAlgorithm;
import pppcodes.PPPCodeIndexFile;
import pppcodes.ids.LocatorStringIntConvertor;
import pppcodes.index.persistent.PPPCodeLeafCellFile;

/**
 * This is an algorithm for PPP Codes that internally uses several standard M-Index algorithms.
 * 
 * @author David Novak, Masaryk University, Brno, Czech Republic, novak.david@gmail.com
 */
public class PPPCodeAlgorithmFile extends PPPCodeAlgorithm {
    
    /** Class id for serialization. */
    private static final long serialVersionUID = 212002L;

    /**
     * Creates a new multi-algorithm overlay for the given collection of algorithms.
     * @param algorithms the algorithms on which the operations are processed
     */
    @Algorithm.AlgorithmConstructor(description = "Constructor with created algorithms", arguments = {"array of running algorithms"})
    public PPPCodeAlgorithmFile(Algorithm[] algorithms) {
        super(algorithms);
    }

    /**
     * Creates a new multi-algorithm overlay for the given collection of algorithms.
     * @param algorithms the algorithms on which the operations are processed
     * @param locatorConvertor convertor used for string-integer locator conversion and back again
     */
    @Algorithm.AlgorithmConstructor(description = "Constructor with created algorithms", arguments = {"array of running algorithms", "converter of locator strings to integer"})
    public PPPCodeAlgorithmFile(Algorithm[] algorithms, LocatorStringIntConvertor locatorConvertor) {
        super(algorithms, locatorConvertor);
    }
    
    /**
     * Checks all the M-Index algorithms, if their dynamic cell tree was not modified and
     *  serializes the whole algorithm if it was changed. THis method is typically called
     *  periodically.
     * @param serializationFile file to serialize the whole algorithm into
     * @throws IOException if the serialization failed
     */
    @Override
    public void checkModifiedAndStore(String serializationFile) throws IOException {
        serializingLock.lock();
        try {
            boolean anyModified = false;
            for (MIndexAlgorithm mIndexAlgorithm : algorithms) {
                anyModified = anyModified || mIndexAlgorithm.getmIndex().isDynamicTreeModified();
            }
            if (anyModified) {
                // Store algorithm to file
                this.storeToFile(serializationFile);
            }
        } finally {
            serializingLock.unlock();
        }
    }   
    
    /**
     * If the PPP-Codes are configured using {@link PPPCodeIndexFile} then this method can
     *  set the storage to be used to store the leave node data. This method is efficient only
     *  for the first time - after that all leaves have links to a specific storage.
     * @param leafStorage disk storage to store the leaf data of all PPP-Code overlays
     */
    public void setLeafStorage(DiskStorage<PPPCodeLeafCellFile.PPPCodeLeafData> leafStorage) throws IllegalStateException, BucketStorageException {
        consolidateTreeData();
        for (PPPCodeSingleAlgorithm singleAlg : algorithms) {
            if (singleAlg.getmIndex() instanceof PPPCodeIndexFile) {
                ((PPPCodeIndexFile) singleAlg.getmIndex()).setLeafStorage(leafStorage);
            }
        }
        Logger.getLogger(PPPCodeAlgorithmFile.class.getName()).log(Level.INFO, "leaf disk storage set to: {0}", leafStorage.getFile());
    }

}
+6 −0
Original line number Diff line number Diff line
@@ -94,4 +94,10 @@ public class GetJoinCandidatesProcessor extends OneStepNavigationProcessor<GetJo
        }
    }

    @Override
    public void close() {
        if (! operation.isFinished()) {
            operation.endOperation();
        }
    }    
}