Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SequenceHash.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SequenceHash.cpp
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #include "SequenceHash.hpp"
00007 
00008 using namespace benzene;
00009 
00010 //----------------------------------------------------------------------------
00011 
00012 namespace
00013 {
00014     
00015 struct HashData
00016 {
00017     HashData();
00018     hash_t hashes[BITSETSIZE][BITSETSIZE];
00019 };
00020 
00021 HashData::HashData()
00022 {
00023     for (int i = 0; i < BITSETSIZE; ++i)
00024         for (int j = 0; j < BITSETSIZE; ++j)
00025             hashes[i][j] = HashUtil::RandomHash();
00026 }
00027 
00028 const HashData& GetHashData()
00029 {
00030     static HashData data;
00031     return data;
00032 }
00033 
00034 } // namespace
00035 
00036 //----------------------------------------------------------------------------
00037 
00038 hash_t SequenceHash::Hash(const PointSequence& seq)
00039 {
00040     HexAssert((int)seq.size() < BITSETSIZE);
00041 
00042     const HashData& data = GetHashData();
00043 
00044     hash_t ret = 0;
00045     for (std::size_t i = 0; i < seq.size(); ++i) 
00046         ret ^= data.hashes[i][seq[i]];
00047 
00048     return ret;
00049 }
00050 
00051 
00052 hash_t SequenceHash::Hash(const MoveSequence& seq)
00053 {
00054     HexAssert((int)seq.size() < BITSETSIZE);
00055 
00056     const HashData& data = GetHashData();
00057 
00058     hash_t ret = 0;
00059     for (std::size_t i = 0; i < seq.size(); ++i) 
00060         ret ^= data.hashes[i][seq[i].point()];
00061 
00062     return ret;
00063 }
00064 
00065 //----------------------------------------------------------------------------


6 Jan 2011 Doxygen 1.6.3