1

How can I ensure that an element is in my HASH_TABLE, if it is detachable?

Current = HASH_TABLE[ARRAYED_SET[G], G]

add_edge (src: G; dst: G)
do
    if attached Current.at(src) as edges then
        edges.put(dst)
    end
ensure
    in: Current.at (src).has (dst)
end
Ferenc Dajka
  • 1,052
  • 3
  • 17
  • 45

1 Answers1

1

Have you try that:

add_edge (src: G; dst: G)
do
    if attached Current.at(src) as edges then
        edges.put(dst)
    end
ensure
    in: attached Current.at (src) as edges implies edges.has (dst)
end
Louis M
  • 576
  • 2
  • 4
  • 1
    Change the postcondition to use 'implies' instead of 'and then': in: attached at(src) as edges implies edges.has(dst) – Zoran Simic Jan 05 '14 at 22:24
  • I do think that "attached Current.at (src)" is a valid post-condition and should be check also. If you use "implies" instead of "and then", the fact that "Current.at (src)" is Void will be considered a valid state of 'Current' after the procedure and of course it is not the case. So, that is why the "and then". – Louis M Jan 06 '14 at 00:05
  • The code is a no-op if src isn't attached... you should then specify in precondition: attached at(src) – Zoran Simic Jan 06 '14 at 00:31
  • True, sorry. I forget that G is not an attached type. – Louis M Jan 06 '14 at 00:41