Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/MutableMap/MutableMapExamples.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module {:options "-functionSyntax:4"} MutableMapExamples {
}

method Main() {
var m := new MutableMap<string,string>();
var m := new MutableMap((k: string, v: string) => true, false);
AssertAndExpect(m.Keys() == {});
AssertAndExpect(m.Values() == {});
AssertAndExpect(m.Items() == {});
Expand Down
9 changes: 7 additions & 2 deletions src/MutableMap/MutableMap.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ module {:extern "DafnyLibraries"} {:options "-functionSyntax:4"} DafnyLibraries
}

class {:extern} MutableMap<K(==),V(==)> extends MutableMapTrait<K,V> {
constructor {:extern} ()
ensures this.content() == map[]

// Invariant on key-value pairs this map may hold
ghost const inv: (K, V) -> bool

constructor {:extern} (ghost inv: (K, V) -> bool, bytesKeys: bool := false)
ensures 0 == |this.content().Items|
Comment thread
ssomayyajula marked this conversation as resolved.
Outdated
ensures this.inv == inv

function {:extern} content(): map<K, V>
reads this
Expand Down
8 changes: 7 additions & 1 deletion src/MutableMap/MutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
public class MutableMap<K, V> implements DafnyLibraries.MutableMapTrait<K, V> {
private ConcurrentHashMap<K,V> m;

public MutableMap(dafny.TypeDescriptor<K> _td_K, dafny.TypeDescriptor<V> _td_V) {
// TODO: remove bytesKeys boolean https://github.com/dafny-lang/dafny/issues/6333
public MutableMap(
dafny.TypeDescriptor<K> _td_K,
dafny.TypeDescriptor<V> _td_V,
boolean bytesKeys) {
m = new ConcurrentHashMap<K,V>();
}

public void __ctor(boolean bytesKeys) {}

@Override
public DafnyMap<K,V> content() {
return new DafnyMap<K,V>(m);
Expand Down