github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library@v0.2.0/DafnyLibraries/externs.go (about) 1 package DafnyLibraries 2 3 import ( 4 sync "sync" 5 6 Std_Wrappers "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers" 7 _dafny "github.com/dafny-lang/DafnyRuntimeGo/v4/dafny" 8 ) 9 10 // Definition of class MutableMap copied over from 11 // https://github.com/dafny-lang/dafny/blob/master/Source/DafnyStandardLibraries/src/Std_Concurrent/Std_Concurrent.go 12 type MutableMap struct { 13 mu sync.Mutex 14 15 Internal _dafny.Map 16 } 17 18 func New_MutableMap_() *MutableMap { 19 return &MutableMap{} 20 } 21 22 type CompanionStruct_MutableMap_ struct { 23 } 24 25 var Companion_MutableMap_ = CompanionStruct_MutableMap_{} 26 27 func (_this *MutableMap) Equals(other *MutableMap) bool { 28 return _this == other 29 } 30 31 func (_this *MutableMap) EqualsGeneric(x interface{}) bool { 32 other, ok := x.(*MutableMap) 33 return ok && _this.Equals(other) 34 } 35 36 func (*MutableMap) String() string { 37 return "ExternConcurrent.MutableMap" 38 } 39 40 func Type_MutableMap_(Type_K_ _dafny.TypeDescriptor, Type_V_ _dafny.TypeDescriptor) _dafny.TypeDescriptor { 41 return type_MutableMap_{Type_K_, Type_V_} 42 } 43 44 type type_MutableMap_ struct { 45 Type_K_ _dafny.TypeDescriptor 46 Type_V_ _dafny.TypeDescriptor 47 } 48 49 func (_this type_MutableMap_) Default() interface{} { 50 return (*MutableMap)(nil) 51 } 52 53 func (_this type_MutableMap_) String() string { 54 return "ExternConcurrent.MutableMap" 55 } 56 func (_this *MutableMap) ParentTraits_() []*_dafny.TraitID { 57 return [](*_dafny.TraitID){} 58 } 59 60 var _ _dafny.TraitOffspring = &MutableMap{} 61 62 func (_this *MutableMap) Ctor__() { 63 { 64 } 65 } 66 func (_this *MutableMap) Keys() _dafny.Set { 67 { 68 _this.mu.Lock() 69 defer _this.mu.Unlock() 70 71 return _this.Internal.Keys() 72 } 73 } 74 func (_this *MutableMap) HasKey(k interface{}) bool { 75 { 76 _this.mu.Lock() 77 defer _this.mu.Unlock() 78 79 return _this.Internal.Contains(k) 80 } 81 } 82 func (_this *MutableMap) Values() _dafny.Set { 83 { 84 _this.mu.Lock() 85 defer _this.mu.Unlock() 86 87 return _this.Internal.Values() 88 } 89 } 90 func (_this *MutableMap) Items() _dafny.Set { 91 { 92 _this.mu.Lock() 93 defer _this.mu.Unlock() 94 95 return _this.Internal.Items() 96 } 97 } 98 func (_this *MutableMap) Get(k interface{}) Std_Wrappers.Option { 99 { 100 _this.mu.Lock() 101 defer _this.mu.Unlock() 102 103 value, ok := _this.Internal.Find(k) 104 if ok { 105 return Std_Wrappers.Companion_Option_.Create_Some_(value) 106 } else { 107 return Std_Wrappers.Companion_Option_.Create_None_() 108 } 109 } 110 } 111 func (_this *MutableMap) Put(k interface{}, v interface{}) { 112 { 113 _this.mu.Lock() 114 defer _this.mu.Unlock() 115 116 _this.Internal = _this.Internal.UpdateUnsafe(k, v) 117 } 118 } 119 func (_this *MutableMap) Remove(k interface{}) { 120 { 121 _this.mu.Lock() 122 defer _this.mu.Unlock() 123 124 // This could be special-cased for a single remove to be a bit faster, 125 // but it's still going to be O(n) so likely not worth it. 126 _this.Internal = _this.Internal.Subtract(_dafny.SetOf(k)) 127 } 128 } 129 func (_this *MutableMap) Size() _dafny.Int { 130 { 131 _this.mu.Lock() 132 defer _this.mu.Unlock() 133 134 return _this.Internal.Cardinality() 135 } 136 } 137 138 // End of class MutableMap 139 140 // This is handrolled extern 141 func (_this *MutableMap) Select(k interface{}) interface{} { 142 r := _this.Get(k) 143 if r.Is_None() { 144 return nil 145 } 146 return r.Dtor_value() 147 }