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

@ -139,13 +139,16 @@ int main(int argc, char *argv[])
FixedList<label, 4> list1{2, 3, 4, 5};
Info<< "list1:" << list1
<< " hash:" << FixedList<label, 4>::Hash<>()(list1) << nl;
<< " hash:" << FixedList<label,4>::Hash<>()(list1) << nl
<< " hash:" << Hash<FixedList<label,4>>()(list1) << nl;
label a[4] = {0, 1, 2, 3};
FixedList<label, 4> list2(a);
Info<< "list2:" << list2
<< " hash:" << FixedList<label, 4>::Hash<>()(list2) << nl;
<< " hash:" << FixedList<label,4>::Hash<>()(list2) << nl
<< " hash:" << Hash<FixedList<label,4>>()(list2) << nl;
// Using FixedList for content too
{