bt2: add `__hash__()` method on hashable fields
Implement the `__hash__()` method of selected fields so that they can be
used as keys in dictionaries. This commit only implements the
`__hash__()` method of _NumericFieldConst and _StringFieldConst fields
after considering the following facts:
1. "[...] the implementation of hashable collections requires that a key’s
hash value is immutable (if the object’s hash value changes, it will be
in the wrong hash bucket)." [1],
2. Python built-in types bool, int, float, and string are hashable,
and sequences and dictionaries are not.
So I suggest that only const fields should be hashable as they are
immutable, and that Container fields (variant, static array, etc.) should not
be hashable (even if they are const) to be consistent with Python
built-in types.
[1]: https://docs.python.org/3/reference/datamodel.html?highlight=__hash__#object.__hash__
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I3dc246802d628603a3f06ecd3a87b7e38b3f1e27
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2032
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
This page took 0.029099 seconds and 4 git commands to generate.