-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMutableMap.cs
More file actions
78 lines (67 loc) · 1.82 KB
/
Copy pathMutableMap.cs
File metadata and controls
78 lines (67 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
* Copyright by the contributors to the Dafny Project
* SPDX-License-Identifier: MIT
*******************************************************************************/
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.Numerics;
using _System;
using Dafny;
namespace DafnyLibraries {
public partial class MutableMap<K, V>
{
private ConcurrentDictionary<K, V> m;
public MutableMap() {
m = new ConcurrentDictionary<K, V>();
}
public IMap<K, V> content() {
var keyPairs = new List<IPair<K, V>>();
foreach (var k in m.Keys) {
keyPairs.Add(new Pair<K, V>(k, m[k]));
}
return Map<K, V>.FromCollection(keyPairs);
}
public void Put(K k, V v)
{
m[k] = v;
}
public Dafny.ISet<K> Keys()
{
var keys = m.Keys;
return Set<K>.FromCollection(keys);
}
public bool HasKey(K k)
{
return m.ContainsKey(k);
}
public Dafny.ISet<V> Values()
{
var values= m.Values;
return Set<V>.FromCollection(values);
}
public Dafny.ISet<_ITuple2<K, V>> Items()
{
var keyPairs = new List<_ITuple2<K, V>>();
foreach (var k in m.Keys) {
keyPairs.Add(new Tuple2<K, V>(k, m[k]));
}
return Set<_ITuple2<K,V>>.FromCollection(keyPairs);
}
public V Select(K k)
{
return m[k];
}
public void Remove(K k)
{
if (HasKey(k)) {
var keypair = new KeyValuePair<K, V>(k, m[k]);
m.TryRemove(keypair);
}
}
public BigInteger Size()
{
return new BigInteger(m.Count);
}
}
}