Commit 83263463 authored by Fernando Silva Coira's avatar Fernando Silva Coira
Browse files

Initial commit

parents
Pipeline #78 canceled with stages

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.
cmake_minimum_required(VERSION 2.8.4)
project(knTreap)
#projects
#set(CMAKE_BUILD_TYPE "Debug")
add_subdirectory(./CPlusPlus)
cmake_minimum_required(VERSION 2.8.4)
project(kntreapCPP)
set(PROJECT_VENDOR "Fernando Silva")
set(CMAKE_PROJECT_NAME "kn-treap")
set(PROJECT_CONTACT "fernando.silva@udc.es")
set(CMAKE_INSTALL_PREFIX /home/fsilva/software)
set(CMAKE_COMPILER_IS_GNUCXX)
# Set output folder
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include_directories(./include/)
set(SOURCES
src/HierarchyStructure/QNodeHS.cpp
src/HierarchyStructure/HierarchyStructure.cpp
src/kn-treap/util/QNodeN.cpp
src/kn-treap/util/PathEntry.cpp
src/kn-treap/util/BufferPathEntry.cpp
src/kn-treap/util/SummaryQueue.cpp
src/rtree/GetObjectsQueryBasic.cpp
src/rtree/Statistic/QueryStrategy/GetObjectsQueryCell.cpp
src/k2-treap/max/k2-treap-max.cpp
src/kn-treap/kn-treap-base.cpp
src/kn-treap/sum/kn-treap-sum.cpp
src/kn-treap/sum/kn-treap-sum-mm.cpp
src/k2-treap/max/util/basic.cpp
src/k2-treap/max/util/bitrankw32int.cpp
src/k2-treap/max/util/BST.cpp
src/k2-treap/max/util/CellSequence.cpp
src/k2-treap/max/util/directcodes.cpp
src/k2-treap/max/util/PriorityQueue.cpp
src/k2-treap/max/util/query.cpp
src/k2-treap/max/util/Queue.cpp
src/k2-treap/max/util/spk2tree.cpp)
# Flags
set(CMAKE_CXX_FLAGS " -Wall -m64")
set(CMAKE_CXX_FLAGS_RELEASE " -std=c++0x -Wall -O9")
set(CMAKE_CXX_FLAGS_DEBUG " -std=c++0x -O9 ")
#set(CMAKE_CXX_FLAGS_DEBUG " -std=c++0x -g3 -DDEBUG")
#set(CMAKE_CXX_FLAGS_DEBUG " -std=c++0x -pg ")
# set default compilation and show details for debug build
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_VERBOSE_MAKEFILE ON)
endif (NOT CMAKE_BUILD_TYPE)
# Create the library
add_library(kntreap STATIC ${SOURCES})
install(TARGETS kntreap DESTINATION lib)
install(DIRECTORY "includes" DESTINATION includes/libkntreap)
#Add libraries
# Add libcds
set(LIBCDS_DIR "./libs/libcds2/")
include_directories(${LIBCDS_DIR})
include_directories(${LIBCDS_DIR}includes/)
add_subdirectory(${LIBCDS_DIR})
# Add libspatialindex
set(LIBSPTATIALINDEX_DIR "./libs/spatialindex/")
include_directories(${LIBSPTATIALINDEX_DIR})
include_directories(${LIBSPTATIALINDEX_DIR}include/)
include_directories(${LIBSPTATIALINDEX_DIR}include/spatialindex)
add_subdirectory(${LIBSPTATIALINDEX_DIR})
#Add libUtils
set(LIBUTILS_DIR "./libs/libUtils/")
include_directories(${LIBUTILS_DIR})
include_directories(${LIBUTILS_DIR}include/)
add_subdirectory(${LIBUTILS_DIR})
# Executables k2-treap
add_executable(EncodeK2Treap ./src/exec/k2-treap/encodeK2Treap.cpp)
add_executable(GetMaxMinTopKCellByCell ./src/exec/Statistic/statisticRTreeMaxTopKCellByCell.cpp)
# Executables kn-treap
add_executable(EncodeknTreapDW ./src/encodeDW.cpp)
add_executable(EncodeknTreapMMDW ./src/encodeMMDW.cpp)
add_executable(TestQueriesknTreapsDW ./src/testQueriesDW.cpp)
add_executable(TestQueriesknTreapsMMDW ./src/testQueriesMMDW.cpp)
# Target libraries k2-treap
target_link_libraries(EncodeK2Treap LINK_PUBLIC kntreap spatialindex)
target_link_libraries(GetMaxMinTopKCellByCell LINK_PUBLIC kntreap cds spatialindex)
# Target libraries kn-treap
target_link_libraries(EncodeknTreapDW LINK_PUBLIC kntreap cds utils)
target_link_libraries(EncodeknTreapMMDW LINK_PUBLIC kntreap cds utils)
target_link_libraries(TestQueriesknTreapsDW LINK_PUBLIC kntreap cds utils)
target_link_libraries(TestQueriesknTreapsMMDW LINK_PUBLIC kntreap cds utils)
/*
* Created by Fernando Silva on 13/04/16.
*
* Copyright (C) 2016-current-year, Fernando Silva, all rights reserved.
*
* Author's contact: Fernando Silva <fernando.silva@udc.es>
* Databases Lab, University of A Coruña. Campus de Elviña s/n. Spain
*
* Class to represent the hierarchies of a DataWareHouse
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef KNTREAP_HIERARCHYSTRUCTURE_HS_H_
#define KNTREAP_HIERARCHYSTRUCTURE_HS_H_
#include <fstream>
#include <list>
#include <map>
#include <HierarchyStructure/QNodeHS.h>
namespace hierarchy_structure_static {
class HierarchyStructure {
public:
HierarchyStructure() {};
HierarchyStructure(uint numdimensions, std::list <std::string> dimFiles,
std::list <std::string> bitmapFiles);
HierarchyStructure(uint numdimensions, std::list <std::string> dimFiles);
virtual ~HierarchyStructure();
int* createDataWarehouse(std::ifstream &dataFile);
uint getNumdimensions();
void getPosition(std::string **keys, uint *startPos);
void getPositions(std::string **keys, uint *startPos, uint *endPos);
uint getTotalItems();
uint *getRealSizes();
// File functions
virtual void save(std::ofstream &of) const;
static HierarchyStructure *load(std::ifstream &in);
// Size functions
virtual size_t getTotalSize() const;
virtual size_t printSize() const;
// Print functions
void printKeys() const;
private:
std::map < std::string, QNodeHS * > ** mapDimensions;
uint numDimensions;
uint *realSizes;
uint totalItems;
uint updatePositionsAndMap(QNodeHS *node, std::map < std::string, QNodeHS * > *mapDimensions);
void printStructure(QNodeHS *root);
};
}
#endif // KNTREAP_HIERARCHYSTRUCTURE_HS_H_
/*
* Created by Fernando Silva on 13/04/16.
*
* Copyright (C) 2016-current-year, Fernando Silva, all rights reserved.
*
* Author's contact: Fernando Silva <fernando.silva@udc.es>
* Databases Lab, University of A Coruña. Campus de Elviña s/n. Spain
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef KNTREAP_HIERARCHYSTRUCTURE_QNODEHS_H_
#define DW_QNODEDW_H_
#include <sys/types.h>
#include <string>
namespace hierarchy_structure_static {
class QNodeHS {
public:
QNodeHS() {};
QNodeHS(std::string name, uint level);
QNodeHS(std::string name, uint start, uint end);
~QNodeHS();
std::string name;
uint level;
uint start;
uint end;
QNodeHS **children;
uint numOfChildren;
};
}
#endif // KNTREAP_HIERARCHYSTRUCTURE_QNODEHS_H_
/*
* Created by Fernando Silva on 6/11/17.
*
* Copyright (C) 2017-current-year, Fernando Silva, all rights reserved.
*
*
* Author's contact: Fernando Silva <fernando.silva@udc.es>
* Databases Lab, University of A Coruña. Campus de Elviña s/n. Spain
*
* DESCRIPTION
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef KNTREAP_K2_TREAP_MAX_H_
#define KNTREAP_K2_TREAP_MAX_H_
#include <rtree/Statistic/QueryStrategy/GetObjectsQueryCell.h>
#include <k2-treap/max/util/directcodes.h>
#include <k2-treap/max/util/CellSequence.h>
#include <k2-treap/max/util/PriorityQueue.h>
#include <k2-treap/max/util/Queue.h>
namespace kntreap_static {
typedef struct {
int xini;
int xend;
int yini;
int yend;
int valini;
int valend;
} QUERY;
typedef struct {
int nres;
CellAux * edges;
} QUERYRES;
typedef struct {
int size; // virtual size of the matrix (power of K)
int realSize; // real size of the matrix
uint *onesBeforeLevel; //number of ones before each level
CellSequence ** coordinates; //nlevels-1 lists with the coordinates of the max cell
FTRep * values; //list of max values
bitRankW32Int *bitmap; // k2-tree representation of the data: single bitmap for T:L
uint *divKLevels; //partition point at each level
int nlevels; //height of the tree (+1)
//Only used in version with compression of ones
uint *ones2BeforeLevel; //number of black nodes before each level
bitRankW32Int *bitmap2; // k2-tree representation of the data: single bitmap for Tp
//All versions, but not really part of the structure (mostly used during construction):
uint *firstBitLevel; //start position of each level
uint * sizeLevels;
uint * onesLevels;
uint * ones2Levels;
//All versions: queue and priority queue for interval and top-k queries
PQ *pq;
Q *q;
} KTREAP;
KTREAP * KTREAP_create(int size, int **data);
int KTREAP_getCell(KTREAP * treap, uint row, uint col);
uint KTREAP_getTopK(KTREAP * treap, uint k, uint xini, uint xend, uint yini, uint yend, CellAux * ret);
uint KTREAP_getTopKMBR(KTREAP * treap, uint k, id_type *MBRIds, int *valuesResult, ISpatialIndex *tree, GetObjectsQueryCell *qe);
void KTREAP_query(KTREAP * treap, QUERY q, QUERYRES * res);
void KTREAP_delete(KTREAP * treap);
void KTREAP_save(KTREAP * treap, FILE * f);
KTREAP *KTREAP_load(FILE * f);
} // END namespace kntreap_static
#endif // KNTREAP_K2_TREAP_MAX_H_
/*
* BST.h
*
* Created on: 16/05/2014
* Author: guillermo
*/
#ifndef BST_H_
#define BST_H_
typedef struct sBSTNODE {
struct sBSTNODE *left;
struct sBSTNODE *right;
void *key;
} BSTNODE;
typedef struct {
int capacity;
BSTNODE * root;
int (*comparator)(void * v1, void *v2);
//private
int currentEntry;
BSTNODE *entries;
} BST;
BST *BST_create(int capacity, int (*comparator)(void *, void *));
/*
* Checks if the element existed. If it did, it returns 0 and exits.
* If the element did not exist, it is added and the method returns 1;
*/
int BST_insertIfNeeded(BST *tree, void * key);
#endif /* BST_H_ */
/*
* CellSequence.h
*
* Created on: 31/03/2014
* Author: guillermo
*/
#ifndef CELLSEQUENCE_H_
#define CELLSEQUENCE_H_
#include <k2-treap/max/util/basic.h>
typedef struct sC {
uint row;
uint col;
} Cell;
typedef struct {
uint baserow;
uint basecol;
uint row;
uint col;
uint value;
uint uniform;
} CellAux;
typedef struct sCS {
int coordinateSize;
uint nElements;
uint *data;
} CellSequence;
CellSequence *CS_create(int coordinateSize, uint nElements);
void CS_set(CellSequence *seq, uint pos, uint row, uint col);
Cell CS_get(CellSequence *seq, uint pos);
void CS_delete(CellSequence * seq);
void CS_save(CellSequence *seq, FILE * f);
CellSequence *CS_load(FILE * f);
#endif /* CELLSEQUENCE_H_ */
/*
* k2treap.h
*
* Created on: 31/03/2014
* Author: guillermo
*/
#ifndef K2TREAP_H_
#define K2TREAP_H_
#include <k2-treap/max/util/directcodes.h>
#include <k2-treap/max/util/CellSequence.h>
#include <k2-treap/max/util/PriorityQueue.h>
#include <k2-treap/max/util/Queue.h>
typedef struct {
int xini;
int xend;
int yini;
int yend;
int valini;
int valend;
} QUERY;
typedef struct {
int nres;
CellAux * edges;
} QUERYRES;
typedef struct {
int size; // virtual size of the matrix (power of K)
int realSize; // real size of the matrix
uint *onesBeforeLevel; //number of ones before each level
CellSequence ** coordinates; //nlevels-1 lists with the coordinates of the max cell
FTRep * values; //list of max values
bitRankW32Int *bitmap; // k2-tree representation of the data: single bitmap for T:L
uint *divKLevels; //partition point at each level
int nlevels; //height of the tree (+1)
//Only used in version with compression of ones
uint *ones2BeforeLevel; //number of black nodes before each level
bitRankW32Int *bitmap2; // k2-tree representation of the data: single bitmap for Tp
//All versions, but not really part of the structure (mostly used during construction):
uint *firstBitLevel; //start position of each level
uint * sizeLevels;
uint * onesLevels;
uint * ones2Levels;
//All versions: queue and priority queue for interval and top-k queries
PQ *pq;
Q *q;
} KTREAP;
KTREAP * KTREAP_create(int size, int **data);
int KTREAP_getCell(KTREAP * treap, uint row, uint col);
uint KTREAP_getTopK(KTREAP * treap, uint k, uint xini, uint xend, uint yini, uint yend, CellAux * ret);
void KTREAP_query(KTREAP * treap, QUERY q, QUERYRES * res);
void KTREAP_delete(KTREAP * treap);
void KTREAP_save(KTREAP * treap, FILE * f);
KTREAP *KTREAP_load(FILE * f);
#endif /* K2TREAP_H_ */
/*
* PriorityQueue.h
*
* Created on: 31/03/2014
* Author: guillermo
*/
#ifndef PRIORITYQUEUE_H_
#define PRIORITYQUEUE_H_
#include <k2-treap/max/util/basic.h>
#include <k2-treap/max/util/CellSequence.h>
typedef struct {
CellAux cellAux;
uint level;
uint position;
} PQNode;
typedef struct {
uint size;
uint maxSize;
PQNode * nodes;
} PQ;
PQ *PQ_create(uint maxSize);
void PQ_add(PQ *pq, CellAux cell, uint level, uint position);
PQNode PQ_pop(PQ *pq);
void PQ_delete(PQ * pq);
int PQ_empty(PQ * pq);
void PQ_print(PQ * pq);
#endif /* PRIORITYQUEUE_H_ */
/*
* PriorityQueue.h
*
* Created on: 31/03/2014
* Author: guillermo
*/
#ifndef QUEUE_H_
#define QUEUE_H_
#include <k2-treap/max/util/basic.h>
#include <k2-treap/max/util/CellSequence.h>
typedef struct {
CellAux cellAux;
uint level;
uint position;
} QNode;
typedef struct {
uint head;
uint tail;
uint maxSize;
QNode * nodes;
} Q;
Q *Q_create(uint maxSize);
void Q_add(Q *q, CellAux cell, uint level, uint position);
QNode Q_pop(Q *q);
void Q_delete(Q * q);
int Q_empty(Q * q);
void Q_print(Q * q);
#endif /* QUEUE_H_ */
#ifndef BASICSINCLUDED
#define BASICSINCLUDED
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/times.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
/* basics.h
Copyright (C) 2005, Rodrigo Gonzalez, all rights reserved.
Some preliminary stuff
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define FREAD(p,s,n,f) {int v = fread(p,s,n,f); if (v != n) {printf("FREAD failed!\n");exit(-1);}}
#define FWRITE(p,s,n,f) {int v = fwrite(p,s,n,f); if (v != n) {printf("FWRITE failed!\n");exit(-1);}}
#define mask31 0x0000001F
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
/*numero de bits del entero de la maquina*/
#define W 32
/* W-1 */
#define Wminusone 31
/*numero de bits del entero de la maquina*/
#define WW 64
/*bits para hacer la mascara para contar mas rapido*/
#define bitsM 8
/*bytes que hacen una palabra */
#define BW 4
#ifndef uchar
#define uchar unsigned char