bitwalker / libgraph

A graph data structure library for Elixir projects
MIT License
524 stars 75 forks source link

v0.11.0 add_vertex finds old label if new label is nil #5

Closed ianrumford closed 6 years ago

ianrumford commented 6 years ago

Environment

Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

Elixir 1.5.1

Ubuntu 16.04

Current behavior

Test is:

  1. add a vertex with a non-nil label
  2. delete the vertex
  3. add the same vertex with nil label
  4. get the vertex's label

The comparisons at the end confirms the label is the original one.

v1 = :v1
l1a = :l1a
l1b = nil

g = Graph.new()

g = g |> Graph.add_vertex(v1, l1a)

g = g |> Graph.delete_vertex(v1)

g = g |> Graph.add_vertex(v1, l1b)

l1c = g |> Graph.vertex_label(v1)

true = (l1c == l1a)
false = (l1c == l1b)

A quick look at the graph's stuct shows the old label to have been retained in the vertex_labels after the delete_vertex.

Expected behavior

The nil label should be used.