hash specialization for std::hash<tf::Task>
hash specialization for std::hash<tf::TaskView>
The hash value of a tf::Task is computed based on the underlying task node pointer. Two tf::Task objects have the same hash value if and only if they reference the same underlying node in the taskflow graph.
- Equality and Inequality
Two tf::Task objects are:
- Equal in hash: when they reference the same task node (same pointer)
- Unequal in hash: when they reference different task nodes
tf::Task objects created from different taskflow calls or different task insertions will have different hash values, even if they represent logically similar work. The hash function is based on the associated object identity (i.e., underlying node pointer), not semantic equivalence.
tf::Task task1_copy = task1;
assert(std::hash<tf::Task>{}(task1) == std::hash<tf::Task>{}(task1_copy));
assert(std::hash<tf::Task>{}(task1) != std::hash<tf::Task>{}(task2));
std::unordered_set<tf::Task> task_set;
task_set.insert(task1);
task_set.insert(task2);
assert(task_set.size() == 2);
task_set.insert(task1_copy);
assert(task_set.size() == 2);
Task emplace(C &&callable)
creates a static task
Definition flow_builder.hpp:1562
class to create a task handle over a taskflow node
Definition task.hpp:569
class to create a taskflow object
Definition taskflow.hpp:64
- See also
- tf::Task::hash_value() for obtaining the hash value directly.
The hash value of a tf::TaskView is computed based on the underlying task node address. Two tf::TaskView objects have the same hash value if and only if they reference the same underlying node in the taskflow graph. The hash function is based on the associated object identity (i.e., underlying node pointer), not semantic equivalence.
- Equality and Inequality
Two tf::TaskView objects are:
- Equal in hash: when they reference the same task node
- Unequal in hash: when they reference different task nodes
Since tf::TaskView is a lightweight read-only view (typically passed by reference or returned by graph traversal functions), hash equality follows the same node identity principle as tf::Task: it depends on which task node is being viewed, not on any semantic property of the task.
tf::TaskView view1 = task1;
tf::TaskView view2 = task2;
tf::TaskView view1_copy = task1;
assert(std::hash<tf::TaskView>{}(view1) == std::hash<tf::TaskView>{}(view1_copy));
assert(std::hash<tf::TaskView>{}(view1) != std::hash<tf::TaskView>{}(view2));
assert(std::hash<tf::TaskView>{}(view1) == std::hash<tf::Task>{}(task1));
std::unordered_map<tf::TaskView, int> task_map;
task_map[view1] = 10;
task_map[view2] = 20;
assert(task_map[view1_copy] == 10);
- See also
- tf::TaskView::hash_value() for obtaining the hash value directly.