Cache-Aware preprocessing with less space requirements
This commit is contained in:
parent
fd88aba8a1
commit
f60f676563
@ -38,6 +38,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#include "../DataStructures/DynamicGraph.h"
|
#include "../DataStructures/DynamicGraph.h"
|
||||||
#include "../DataStructures/Percent.h"
|
#include "../DataStructures/Percent.h"
|
||||||
#include "../DataStructures/XORFastHash.h"
|
#include "../DataStructures/XORFastHash.h"
|
||||||
|
#include "../DataStructures/XORFastHashStorage.h"
|
||||||
#include "../Util/OpenMPReplacement.h"
|
#include "../Util/OpenMPReplacement.h"
|
||||||
#include "../Util/StringUtil.h"
|
#include "../Util/StringUtil.h"
|
||||||
|
|
||||||
@ -66,7 +67,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef DynamicGraph< _ContractorEdgeData > _DynamicGraph;
|
typedef DynamicGraph< _ContractorEdgeData > _DynamicGraph;
|
||||||
typedef BinaryHeap< NodeID, NodeID, int, _HeapData > _Heap;
|
// typedef BinaryHeap< NodeID, NodeID, int, _HeapData, ArrayStorage<NodeID, NodeID> > _Heap;
|
||||||
|
typedef BinaryHeap< NodeID, NodeID, int, _HeapData, XORFastHashStorage<NodeID, NodeID> > _Heap;
|
||||||
typedef _DynamicGraph::InputEdge _ContractorEdge;
|
typedef _DynamicGraph::InputEdge _ContractorEdge;
|
||||||
|
|
||||||
struct _ThreadData {
|
struct _ThreadData {
|
||||||
@ -91,7 +93,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _NodePartitionor {
|
struct _NodePartitionor {
|
||||||
bool operator()( std::pair< NodeID, bool > & nodeData ) const {
|
inline bool operator()( std::pair< NodeID, bool > & nodeData ) const {
|
||||||
return !nodeData.second;
|
return !nodeData.second;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -41,27 +41,55 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
10: ret
|
10: ret
|
||||||
|
|
||||||
*/
|
*/
|
||||||
class XORFastHash {
|
class XORFastHash { //65k entries
|
||||||
std::vector<unsigned char> table1;
|
std::vector<unsigned short> table1;
|
||||||
std::vector<unsigned char> table2;
|
std::vector<unsigned short> table2;
|
||||||
public:
|
public:
|
||||||
XORFastHash() {
|
XORFastHash() {
|
||||||
table1.resize(1 << 16);
|
table1.resize(2 << 16);
|
||||||
table2.resize(1 << 16);
|
table2.resize(2 << 16);
|
||||||
for(unsigned i = 0; i < (1 << 16); ++i) {
|
for(unsigned i = 0; i < (2 << 16); ++i) {
|
||||||
table1[i] = i; table2[i];
|
table1[i] = i; table2[i];
|
||||||
}
|
}
|
||||||
std::random_shuffle(table1.begin(), table1.end());
|
std::random_shuffle(table1.begin(), table1.end());
|
||||||
std::random_shuffle(table2.begin(), table2.end());
|
std::random_shuffle(table2.begin(), table2.end());
|
||||||
}
|
}
|
||||||
unsigned short operator()(const unsigned originalValue) const {
|
|
||||||
|
inline unsigned short operator()(const unsigned originalValue) const {
|
||||||
unsigned short lsb = ((originalValue) & 0xffff);
|
unsigned short lsb = ((originalValue) & 0xffff);
|
||||||
unsigned short msb = (((originalValue) >> 16) & 0xffff);
|
unsigned short msb = (((originalValue) >> 16) & 0xffff);
|
||||||
return table1[lsb] ^ table2[msb];
|
return table1[lsb] ^ table2[msb];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class XORMiniHash { //256 entries
|
||||||
|
std::vector<unsigned char> table1;
|
||||||
|
std::vector<unsigned char> table2;
|
||||||
|
std::vector<unsigned char> table3;
|
||||||
|
std::vector<unsigned char> table4;
|
||||||
|
|
||||||
|
public:
|
||||||
|
XORMiniHash() {
|
||||||
|
table1.resize(1 << 8);
|
||||||
|
table2.resize(1 << 8);
|
||||||
|
table3.resize(1 << 8);
|
||||||
|
table4.resize(1 << 8);
|
||||||
|
for(unsigned i = 0; i < (1 << 8); ++i) {
|
||||||
|
table1[i] = i; table2[i];
|
||||||
|
table3[i] = i; table4[i];
|
||||||
|
}
|
||||||
|
std::random_shuffle(table1.begin(), table1.end());
|
||||||
|
std::random_shuffle(table2.begin(), table2.end());
|
||||||
|
std::random_shuffle(table3.begin(), table3.end());
|
||||||
|
std::random_shuffle(table4.begin(), table4.end());
|
||||||
|
}
|
||||||
|
unsigned char operator()(const unsigned originalValue) const {
|
||||||
|
unsigned char byte1 = ((originalValue) & 0xff);
|
||||||
|
unsigned char byte2 = ((originalValue >> 8) & 0xff);
|
||||||
|
unsigned char byte3 = ((originalValue >> 16) & 0xff);
|
||||||
|
unsigned char byte4 = ((originalValue >> 24) & 0xff);
|
||||||
|
return table1[byte1] ^ table2[byte2] ^ table3[byte3] ^ table4[byte4];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* FASTXORHASH_H_ */
|
#endif /* FASTXORHASH_H_ */
|
||||||
|
80
DataStructures/XORFastHashStorage.h
Normal file
80
DataStructures/XORFastHashStorage.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
open source routing machine
|
||||||
|
Copyright (C) Dennis Luxen, others 2010
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU AFFERO General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program 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 Affero General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XORFASTHASHSTORAGE_H_
|
||||||
|
#define XORFASTHASHSTORAGE_H_
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
#include <vector>
|
||||||
|
#include <bitset>
|
||||||
|
|
||||||
|
#include "XORFastHash.h"
|
||||||
|
|
||||||
|
template< typename NodeID, typename Key >
|
||||||
|
class XORFastHashStorage {
|
||||||
|
public:
|
||||||
|
struct HashCell{
|
||||||
|
Key key;
|
||||||
|
NodeID id;
|
||||||
|
unsigned time;
|
||||||
|
HashCell() : key(UINT_MAX), id(UINT_MAX), time(UINT_MAX) {}
|
||||||
|
|
||||||
|
HashCell(const HashCell & other) : key(other.key), id(other.id), time(other.time) { }
|
||||||
|
|
||||||
|
inline operator Key() const {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void operator=(const Key & keyToInsert) {
|
||||||
|
key = keyToInsert;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
XORFastHashStorage( size_t size ) : positions(2<<16), currentTimestamp(0) { }
|
||||||
|
|
||||||
|
inline HashCell& operator[]( const NodeID node ) {
|
||||||
|
unsigned short position = fastHash(node);
|
||||||
|
while((positions[position].time == currentTimestamp) && (positions[position].id != node)){
|
||||||
|
++position %= (2<<16);
|
||||||
|
}
|
||||||
|
|
||||||
|
positions[position].id = node;
|
||||||
|
positions[position].time = currentTimestamp;
|
||||||
|
return positions[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Clear() {
|
||||||
|
++currentTimestamp;
|
||||||
|
if(UINT_MAX == currentTimestamp) {
|
||||||
|
positions.clear();
|
||||||
|
positions.resize((2<<16));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
XORFastHashStorage() : positions(2<<16), currentTimestamp(0) {}
|
||||||
|
std::vector<HashCell> positions;
|
||||||
|
XORFastHash fastHash;
|
||||||
|
unsigned currentTimestamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XORFASTHASHSTORAGE_H_ */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user