Commit 4808e10c authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

used hash64 for key() function

parent 9ef635d5
...@@ -72,7 +72,7 @@ namespace uniset ...@@ -72,7 +72,7 @@ namespace uniset
const ObjectId AdminID = -2; /*!< сервисный идентификатор используемый утилитой admin */ const ObjectId AdminID = -2; /*!< сервисный идентификатор используемый утилитой admin */
typedef size_t KeyType; /*!< уникальный ключ объекта */ typedef uint64_t KeyType; /*!< уникальный ключ объекта */
/*! генератор уникального положительного ключа /*! генератор уникального положительного ключа
* Уникальность гарантируется только для пары значений id и node. * Уникальность гарантируется только для пары значений id и node.
......
...@@ -276,7 +276,7 @@ namespace uniset ...@@ -276,7 +276,7 @@ namespace uniset
{ {
if( it.getIntProp("idfromfile") == 0 ) if( it.getIntProp("idfromfile") == 0 )
{ {
shared_ptr<ObjectIndex_XML> oi = make_shared<ObjectIndex_XML>(unixml); //(fileConfName); shared_ptr<ObjectIndex_hashXML> oi = make_shared<ObjectIndex_hashXML>(unixml); //(fileConfName);
oind = static_pointer_cast<ObjectIndex>(oi); oind = static_pointer_cast<ObjectIndex>(oi);
} }
else else
......
...@@ -732,10 +732,20 @@ string uniset::BadSymbolsToStr() ...@@ -732,10 +732,20 @@ string uniset::BadSymbolsToStr()
return bad; return bad;
} }
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
struct keys_t {
uniset::ObjectId id;
uniset::ObjectId node;
keys_t( const uniset::ObjectId& _id, const uniset::ObjectId& _node ):
id(_id),
node(_node)
{}
};
uniset::KeyType uniset::key( const uniset::ObjectId id, const uniset::ObjectId node ) uniset::KeyType uniset::key( const uniset::ObjectId id, const uniset::ObjectId node )
{ {
//! \warning что тут у нас с переполнением.. keys_t k(id,node);
return KeyType( (id * node) + (id + 2 * node) ); return uniset::hash64( reinterpret_cast<char*>(&k), sizeof(k) );
} }
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
uniset::KeyType uniset::key( const IOController_i::SensorInfo& si ) uniset::KeyType uniset::key( const IOController_i::SensorInfo& si )
......
...@@ -423,3 +423,11 @@ TEST_CASE("UniSetTypes: hash32", "[utypes][hash32]" ) ...@@ -423,3 +423,11 @@ TEST_CASE("UniSetTypes: hash32", "[utypes][hash32]" )
REQUIRE( uniset::hash32("ta") != uniset::hash32("at") ); REQUIRE( uniset::hash32("ta") != uniset::hash32("at") );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: key", "[utypes][key]" )
{
REQUIRE( uniset::key(100,100) == uint64_t(12423972911335977860) );
REQUIRE( uniset::key(100,100) == uint64_t(12423972911335977860) );
REQUIRE( uniset::key(1e14,1e16) == uint64_t(13802851885616383566) );
REQUIRE( uniset::key(101,100) == uint64_t(793928870581810946) );
}
// -----------------------------------------------------------------------------
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment