ENH: add missing Hash function for List/UList (issue #966)

- there were previously no hashing mechanisms for lists so they
  would fall back to the definition for primitives and hash the
  memory location of the allocated List object.

- provide a UList::Hash<> sub-class for inheritance, and also a global
  specialization for UList<T>, List<T> such that the hash value for
  List<List<T>> cascades properly.

- provide similar function in triFace to ensure that it remains
  similar in behaviour to face.

- added SymmHash to Pair, for use when order is unimportant.

STYLE: use string::hash() more consistently

- no particular reason to use Hash<word>() which forwards to
  string::hash() anyhow
This commit is contained in:
Mark Olesen
2018-08-08 23:54:27 +02:00
parent 82bad81d79
commit dd9ecd4988
23 changed files with 712 additions and 345 deletions

View File

@ -598,6 +598,20 @@ int main(int argc, char *argv[])
<< "-wordList: " << flatOutput(wLst) << nl
<< "-stringList: " << flatOutput(sLst) << endl;
// Hash values
{
labelList list1(identity(5));
labelList list2(identity(5));
Info<<"hash of " << flatOutput(list1)
<< " = " << Hash<labelList>()(list1) << " or "
<< labelList::Hash<>()(list1) << nl;
Info<<"hash of " << flatOutput(list2) << " = "
<< Hash<labelList>()(list2) << " or "
<< labelList::Hash<>()(list2) << nl;
}
return 0;
}