/******************************************************************************* * Copyright by the contributors to the Dafny Project * SPDX-License-Identifier: MIT *******************************************************************************/ // RUN: %verify "%s" /** * Specifications that should be satisfied by any implementation of mutable maps. * Possible instantiations are given in "MutableMapDafny.dfy" (not meant for usage, * only exists to verify feasability) and "../../src/MutableMap/MutableMap.dfy" * (meant for usage; interfaces with external code, e.g. "../../src/MutableMap/ * MutableMap.java"). */ module {:options "-functionSyntax:4"} MutableMapTrait { trait {:termination false} MutableMapTrait { function content(): map reads this method Put(k: K, v: V) modifies this ensures this.content() == old(this.content())[k := v] ensures k in old(this.content()).Keys ==> this.content().Values + {old(this.content())[k]} == old(this.content()).Values + {v} ensures k !in old(this.content()).Keys ==> this.content().Values == old(this.content()).Values + {v} function Keys(): (keys: set) reads this ensures keys == this.content().Keys predicate HasKey(k: K) reads this ensures HasKey(k) <==> k in this.content().Keys function Values(): (values: set) reads this ensures values == this.content().Values function Items(): (items: set<(K,V)>) reads this ensures items == this.content().Items ensures items == set k | k in this.content().Keys :: (k, this.content()[k]) function Select(k: K): (v: V) reads this requires this.HasKey(k) ensures v in this.content().Values ensures this.content()[k] == v method Remove(k: K) modifies this ensures this.content() == old(this.content()) - {k} ensures k in old(this.content()).Keys ==> this.content().Values + {old(this.content())[k]} == old(this.content()).Values function Size(): (size: int) reads this ensures size == |this.content().Items| } }