github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library@v0.2.0/JSON_Utils_Vectors/JSON_Utils_Vectors.go (about) 1 // Package JSON_Utils_Vectors 2 // Dafny module JSON_Utils_Vectors compiled into Go 3 4 package JSON_Utils_Vectors 5 6 import ( 7 os "os" 8 9 m_Actions "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Actions" 10 m_Base64 "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Base64" 11 m_Base64Lemmas "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Base64Lemmas" 12 m_BoundedInts "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/BoundedInts" 13 m_DivInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivInternals" 14 m_DivInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivInternalsNonlinear" 15 m_DivMod "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/DivMod" 16 m_FileIO "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/FileIO" 17 m_FloatCompare "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/FloatCompare" 18 m_Functions "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Functions" 19 m_GeneralInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/GeneralInternals" 20 m_GetOpt "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/GetOpt" 21 m_HexStrings "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/HexStrings" 22 m_JSON_Utils_Cursors "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Cursors" 23 m_JSON_Utils_Lexers_Core "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Lexers_Core" 24 m_JSON_Utils_Lexers_Strings "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Lexers_Strings" 25 m_JSON_Utils_Parsers "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Parsers" 26 m_JSON_Utils_Seq "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Seq" 27 m_JSON_Utils_Str "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Str" 28 m_JSON_Utils_Str_CharStrConversion "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Str_CharStrConversion" 29 m_JSON_Utils_Str_CharStrEscaping "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Str_CharStrEscaping" 30 m_JSON_Utils_Views_Core "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Views_Core" 31 m_JSON_Utils_Views_Writers "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/JSON_Utils_Views_Writers" 32 m_Logarithm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Logarithm" 33 m__Math "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Math_" 34 m_ModInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/ModInternals" 35 m_ModInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/ModInternalsNonlinear" 36 m_Mul "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Mul" 37 m_MulInternals "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/MulInternals" 38 m_MulInternalsNonlinear "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/MulInternalsNonlinear" 39 m_Power "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Power" 40 m_Relations "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Relations" 41 m_Seq "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Seq" 42 m_Seq_MergeSort "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Seq_MergeSort" 43 m_Sorting "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Sorting" 44 m_StandardLibrary "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary" 45 m_StandardLibraryInterop "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibraryInterop" 46 m_StandardLibrary_Sequence "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_Sequence" 47 m_StandardLibrary_String "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_String" 48 m_StandardLibrary_UInt "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/StandardLibrary_UInt" 49 m_Streams "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Streams" 50 m_UnicodeStrings "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/UnicodeStrings" 51 m__Unicode "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Unicode_" 52 m_Utf16EncodingForm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Utf16EncodingForm" 53 m_Utf8EncodingForm "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Utf8EncodingForm" 54 m_Wrappers "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers" 55 m__System "github.com/dafny-lang/DafnyRuntimeGo/v4/System_" 56 _dafny "github.com/dafny-lang/DafnyRuntimeGo/v4/dafny" 57 ) 58 59 var _ = os.Args 60 var _ _dafny.Dummy__ 61 var _ m__System.Dummy__ 62 var _ m_Wrappers.Dummy__ 63 var _ m_Relations.Dummy__ 64 var _ m_Seq_MergeSort.Dummy__ 65 var _ m__Math.Dummy__ 66 var _ m_Seq.Dummy__ 67 var _ m_BoundedInts.Dummy__ 68 var _ m__Unicode.Dummy__ 69 var _ m_Functions.Dummy__ 70 var _ m_Utf8EncodingForm.Dummy__ 71 var _ m_Utf16EncodingForm.Dummy__ 72 var _ m_UnicodeStrings.Dummy__ 73 var _ m_FileIO.Dummy__ 74 var _ m_GeneralInternals.Dummy__ 75 var _ m_MulInternalsNonlinear.Dummy__ 76 var _ m_MulInternals.Dummy__ 77 var _ m_Mul.Dummy__ 78 var _ m_ModInternalsNonlinear.Dummy__ 79 var _ m_DivInternalsNonlinear.Dummy__ 80 var _ m_ModInternals.Dummy__ 81 var _ m_DivInternals.Dummy__ 82 var _ m_DivMod.Dummy__ 83 var _ m_Power.Dummy__ 84 var _ m_Logarithm.Dummy__ 85 var _ m_StandardLibraryInterop.Dummy__ 86 var _ m_StandardLibrary_UInt.Dummy__ 87 var _ m_StandardLibrary_Sequence.Dummy__ 88 var _ m_StandardLibrary_String.Dummy__ 89 var _ m_StandardLibrary.Dummy__ 90 var _ m_Streams.Dummy__ 91 var _ m_Sorting.Dummy__ 92 var _ m_HexStrings.Dummy__ 93 var _ m_GetOpt.Dummy__ 94 var _ m_FloatCompare.Dummy__ 95 var _ m_Base64.Dummy__ 96 var _ m_Base64Lemmas.Dummy__ 97 var _ m_Actions.Dummy__ 98 var _ m_JSON_Utils_Views_Core.Dummy__ 99 var _ m_JSON_Utils_Views_Writers.Dummy__ 100 var _ m_JSON_Utils_Lexers_Core.Dummy__ 101 var _ m_JSON_Utils_Lexers_Strings.Dummy__ 102 var _ m_JSON_Utils_Cursors.Dummy__ 103 var _ m_JSON_Utils_Parsers.Dummy__ 104 var _ m_JSON_Utils_Str_CharStrConversion.Dummy__ 105 var _ m_JSON_Utils_Str_CharStrEscaping.Dummy__ 106 var _ m_JSON_Utils_Str.Dummy__ 107 var _ m_JSON_Utils_Seq.Dummy__ 108 109 type Dummy__ struct{} 110 111 // Definition of class Default__ 112 type Default__ struct { 113 dummy byte 114 } 115 116 func New_Default___() *Default__ { 117 _this := Default__{} 118 119 return &_this 120 } 121 122 type CompanionStruct_Default___ struct { 123 } 124 125 var Companion_Default___ = CompanionStruct_Default___{} 126 127 func (_this *Default__) Equals(other *Default__) bool { 128 return _this == other 129 } 130 131 func (_this *Default__) EqualsGeneric(x interface{}) bool { 132 other, ok := x.(*Default__) 133 return ok && _this.Equals(other) 134 } 135 136 func (*Default__) String() string { 137 return "JSON_Utils_Vectors.Default__" 138 } 139 func (_this *Default__) ParentTraits_() []*_dafny.TraitID { 140 return [](*_dafny.TraitID){} 141 } 142 143 var _ _dafny.TraitOffspring = &Default__{} 144 145 func (_static *CompanionStruct_Default___) OOM__FAILURE() m_Wrappers.Outcome { 146 return m_Wrappers.Companion_Outcome_.Create_Fail_(Companion_VectorError_.Create_OutOfMemory_()) 147 } 148 149 // End of class Default__ 150 151 // Definition of datatype VectorError 152 type VectorError struct { 153 Data_VectorError_ 154 } 155 156 func (_this VectorError) Get_() Data_VectorError_ { 157 return _this.Data_VectorError_ 158 } 159 160 type Data_VectorError_ interface { 161 isVectorError() 162 } 163 164 type CompanionStruct_VectorError_ struct { 165 } 166 167 var Companion_VectorError_ = CompanionStruct_VectorError_{} 168 169 type VectorError_OutOfMemory struct { 170 } 171 172 func (VectorError_OutOfMemory) isVectorError() {} 173 174 func (CompanionStruct_VectorError_) Create_OutOfMemory_() VectorError { 175 return VectorError{VectorError_OutOfMemory{}} 176 } 177 178 func (_this VectorError) Is_OutOfMemory() bool { 179 _, ok := _this.Get_().(VectorError_OutOfMemory) 180 return ok 181 } 182 183 func (CompanionStruct_VectorError_) Default() VectorError { 184 return Companion_VectorError_.Create_OutOfMemory_() 185 } 186 187 func (_ CompanionStruct_VectorError_) AllSingletonConstructors() _dafny.Iterator { 188 i := -1 189 return func() (interface{}, bool) { 190 i++ 191 switch i { 192 case 0: 193 return Companion_VectorError_.Create_OutOfMemory_(), true 194 default: 195 return VectorError{}, false 196 } 197 } 198 } 199 200 func (_this VectorError) String() string { 201 switch _this.Get_().(type) { 202 case nil: 203 return "null" 204 case VectorError_OutOfMemory: 205 { 206 return "Vectors.VectorError.OutOfMemory" 207 } 208 default: 209 { 210 return "<unexpected>" 211 } 212 } 213 } 214 215 func (_this VectorError) Equals(other VectorError) bool { 216 switch _this.Get_().(type) { 217 case VectorError_OutOfMemory: 218 { 219 _, ok := other.Get_().(VectorError_OutOfMemory) 220 return ok 221 } 222 default: 223 { 224 return false // unexpected 225 } 226 } 227 } 228 229 func (_this VectorError) EqualsGeneric(other interface{}) bool { 230 typed, ok := other.(VectorError) 231 return ok && _this.Equals(typed) 232 } 233 234 func Type_VectorError_() _dafny.TypeDescriptor { 235 return type_VectorError_{} 236 } 237 238 type type_VectorError_ struct { 239 } 240 241 func (_this type_VectorError_) Default() interface{} { 242 return Companion_VectorError_.Default() 243 } 244 245 func (_this type_VectorError_) String() string { 246 return "JSON_Utils_Vectors.VectorError" 247 } 248 func (_this VectorError) ParentTraits_() []*_dafny.TraitID { 249 return [](*_dafny.TraitID){} 250 } 251 252 var _ _dafny.TraitOffspring = VectorError{} 253 254 // End of datatype VectorError 255 256 // Definition of class Vector 257 type Vector struct { 258 Size uint32 259 Capacity uint32 260 Data _dafny.Array 261 _a interface{} 262 } 263 264 func New_Vector_() *Vector { 265 _this := Vector{} 266 267 _this.Size = uint32(0) 268 _this.Capacity = uint32(0) 269 _this.Data = _dafny.NewArrayWithValue(nil, _dafny.IntOf(0)) 270 _this._a = (interface{})(nil) 271 return &_this 272 } 273 274 type CompanionStruct_Vector_ struct { 275 } 276 277 var Companion_Vector_ = CompanionStruct_Vector_{} 278 279 func (_this *Vector) Equals(other *Vector) bool { 280 return _this == other 281 } 282 283 func (_this *Vector) EqualsGeneric(x interface{}) bool { 284 other, ok := x.(*Vector) 285 return ok && _this.Equals(other) 286 } 287 288 func (*Vector) String() string { 289 return "JSON_Utils_Vectors.Vector" 290 } 291 292 func Type_Vector_(Type_A_ _dafny.TypeDescriptor) _dafny.TypeDescriptor { 293 return type_Vector_{Type_A_} 294 } 295 296 type type_Vector_ struct { 297 Type_A_ _dafny.TypeDescriptor 298 } 299 300 func (_this type_Vector_) Default() interface{} { 301 return (*Vector)(nil) 302 } 303 304 func (_this type_Vector_) String() string { 305 return "JSON_Utils_Vectors.Vector" 306 } 307 func (_this *Vector) ParentTraits_() []*_dafny.TraitID { 308 return [](*_dafny.TraitID){} 309 } 310 311 var _ _dafny.TraitOffspring = &Vector{} 312 313 func (_this *Vector) Ctor__(a0 interface{}, initial__capacity uint32) { 314 { 315 (_this)._a = a0 316 (_this).Size = uint32(0) 317 (_this).Capacity = initial__capacity 318 var _len0_0 _dafny.Int = _dafny.IntOfAny(initial__capacity) 319 _ = _len0_0 320 var _nw0 _dafny.Array 321 _ = _nw0 322 if _len0_0.Cmp(_dafny.Zero) == 0 { 323 _nw0 = _dafny.NewArray(_len0_0) 324 } else { 325 var _init0 func(_dafny.Int) interface{} = (func(_0_a0 interface{}) func(_dafny.Int) interface{} { 326 return func(_1___v0 _dafny.Int) interface{} { 327 return _0_a0 328 } 329 })(a0) 330 _ = _init0 331 var _element0_0 = _init0(_dafny.Zero) 332 _ = _element0_0 333 _nw0 = _dafny.NewArrayFromExample(_element0_0, nil, _len0_0) 334 (_nw0).ArraySet1(_element0_0, 0) 335 var _nativeLen0_0 = (_len0_0).Int() 336 _ = _nativeLen0_0 337 for _i0_0 := 1; _i0_0 < _nativeLen0_0; _i0_0++ { 338 (_nw0).ArraySet1(_init0(_dafny.IntOf(_i0_0)), _i0_0) 339 } 340 } 341 (_this).Data = _nw0 342 } 343 } 344 func (_this *Vector) At(idx uint32) interface{} { 345 { 346 return (_this.Data).ArrayGet1(int(idx)) 347 } 348 } 349 func (_this *Vector) Top() interface{} { 350 { 351 return (_this.Data).ArrayGet1(int((_this.Size) - (func() uint32 { return (uint32(1)) })())) 352 } 353 } 354 func (_this *Vector) Put(idx uint32, a interface{}) { 355 { 356 var _arr0 _dafny.Array = _this.Data 357 _ = _arr0 358 (_arr0).ArraySet1(a, int((idx))) 359 } 360 } 361 func (_this *Vector) CopyFrom(new__data _dafny.Array, count uint32) { 362 { 363 var _hi0 uint32 = count 364 _ = _hi0 365 for _0_idx := uint32(0); _0_idx < _hi0; _0_idx++ { 366 var _arr0 _dafny.Array = _this.Data 367 _ = _arr0 368 (_arr0).ArraySet1((new__data).ArrayGet1(int(_0_idx)), int((_0_idx))) 369 } 370 } 371 } 372 func (_this *Vector) Realloc(new__capacity uint32) { 373 { 374 var _0_old__data _dafny.Array 375 _ = _0_old__data 376 var _1_old__capacity uint32 377 _ = _1_old__capacity 378 var _rhs0 _dafny.Array = _this.Data 379 _ = _rhs0 380 var _rhs1 uint32 = _this.Capacity 381 _ = _rhs1 382 _0_old__data = _rhs0 383 _1_old__capacity = _rhs1 384 var _len0_0 _dafny.Int = _dafny.IntOfAny(new__capacity) 385 _ = _len0_0 386 var _nw0 _dafny.Array 387 _ = _nw0 388 if _len0_0.Cmp(_dafny.Zero) == 0 { 389 _nw0 = _dafny.NewArray(_len0_0) 390 } else { 391 var _init0 func(_dafny.Int) interface{} = func(_2___v1 _dafny.Int) interface{} { 392 return (_this).A() 393 } 394 _ = _init0 395 var _element0_0 = _init0(_dafny.Zero) 396 _ = _element0_0 397 _nw0 = _dafny.NewArrayFromExample(_element0_0, nil, _len0_0) 398 (_nw0).ArraySet1(_element0_0, 0) 399 var _nativeLen0_0 = (_len0_0).Int() 400 _ = _nativeLen0_0 401 for _i0_0 := 1; _i0_0 < _nativeLen0_0; _i0_0++ { 402 (_nw0).ArraySet1(_init0(_dafny.IntOf(_i0_0)), _i0_0) 403 } 404 } 405 var _rhs2 _dafny.Array = _nw0 406 _ = _rhs2 407 var _rhs3 uint32 = new__capacity 408 _ = _rhs3 409 var _lhs0 *Vector = _this 410 _ = _lhs0 411 var _lhs1 *Vector = _this 412 _ = _lhs1 413 _lhs0.Data = _rhs2 414 _lhs1.Capacity = _rhs3 415 (_this).CopyFrom(_0_old__data, _1_old__capacity) 416 } 417 } 418 func (_this *Vector) DefaultNewCapacity(capacity uint32) uint32 { 419 { 420 if (capacity) < ((_this).MAX__CAPACITY__BEFORE__DOUBLING()) { 421 return (uint32(2)) * (capacity) 422 } else { 423 return (_this).MAX__CAPACITY() 424 } 425 } 426 } 427 func (_this *Vector) ReallocDefault() m_Wrappers.Outcome { 428 { 429 var o m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 430 _ = o 431 if (_this.Capacity) == ((_this).MAX__CAPACITY()) { 432 o = m_Wrappers.Companion_Outcome_.Create_Fail_(Companion_VectorError_.Create_OutOfMemory_()) 433 return o 434 } 435 (_this).Realloc((_this).DefaultNewCapacity(_this.Capacity)) 436 o = m_Wrappers.Companion_Outcome_.Create_Pass_() 437 return o 438 return o 439 } 440 } 441 func (_this *Vector) Ensure(reserved uint32) m_Wrappers.Outcome { 442 { 443 var o m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 444 _ = o 445 if (reserved) > (((_this).MAX__CAPACITY()) - (func() uint32 { return (_this.Size) })()) { 446 o = m_Wrappers.Companion_Outcome_.Create_Fail_(Companion_VectorError_.Create_OutOfMemory_()) 447 return o 448 } 449 if (reserved) <= ((_this.Capacity) - (func() uint32 { return (_this.Size) })()) { 450 o = m_Wrappers.Companion_Outcome_.Create_Pass_() 451 return o 452 } 453 var _0_new__capacity uint32 454 _ = _0_new__capacity 455 _0_new__capacity = _this.Capacity 456 for (reserved) > ((_0_new__capacity) - (func() uint32 { return (_this.Size) })()) { 457 _0_new__capacity = (_this).DefaultNewCapacity(_0_new__capacity) 458 } 459 (_this).Realloc(_0_new__capacity) 460 o = m_Wrappers.Companion_Outcome_.Create_Pass_() 461 return o 462 return o 463 } 464 } 465 func (_this *Vector) PopFast() { 466 { 467 (_this).Size = (_this.Size) - (func() uint32 { return (uint32(1)) })() 468 } 469 } 470 func (_this *Vector) PushFast(a interface{}) { 471 { 472 var _arr0 _dafny.Array = _this.Data 473 _ = _arr0 474 var _index0 uint32 = _this.Size 475 _ = _index0 476 (_arr0).ArraySet1(a, int(_index0)) 477 (_this).Size = (_this.Size) + (uint32(1)) 478 } 479 } 480 func (_this *Vector) Push(a interface{}) m_Wrappers.Outcome { 481 { 482 var o m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default() 483 _ = o 484 if (_this.Size) == (_this.Capacity) { 485 var _0_d m_Wrappers.Outcome 486 _ = _0_d 487 var _out0 m_Wrappers.Outcome 488 _ = _out0 489 _out0 = (_this).ReallocDefault() 490 _0_d = _out0 491 if (_0_d).Is_Fail() { 492 o = _0_d 493 return o 494 } 495 } 496 (_this).PushFast(a) 497 o = m_Wrappers.Companion_Outcome_.Create_Pass_() 498 return o 499 return o 500 } 501 } 502 func (_this *Vector) A() interface{} { 503 { 504 return _this._a 505 } 506 } 507 func (_this *Vector) MAX__CAPACITY__BEFORE__DOUBLING() uint32 { 508 { 509 return (m_BoundedInts.Companion_Default___.UINT32__MAX()) / (uint32(2)) 510 } 511 } 512 func (_this *Vector) MAX__CAPACITY() uint32 { 513 { 514 return m_BoundedInts.Companion_Default___.UINT32__MAX() 515 } 516 } 517 518 // End of class Vector