graph: Fix theoretical bug

I've convinced myself that using SLIST_REMOVE() in
graph_remove_last_node() is sufficient to avoid the (pretty
theoretical) bug mentioned in graph_add_edge(). This adds a very small
overhead to graph_remove_last_node() in the common case, but since it
is only used on error paths, that is ok.
graph: Fix stupid bug in rehash function

Obviously, one needs to use the new mask.