github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library@v0.2.0/Seq_MergeSort/Seq_MergeSort.go (about)

     1  // Package Seq_MergeSort
     2  // Dafny module Seq_MergeSort compiled into Go
     3  
     4  package Seq_MergeSort
     5  
     6  import (
     7  	os "os"
     8  
     9  	m_Relations "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Relations"
    10  	m_Wrappers "github.com/aws/aws-cryptographic-material-providers-library/releases/go/smithy-dafny-standard-library/Wrappers"
    11  	m__System "github.com/dafny-lang/DafnyRuntimeGo/v4/System_"
    12  	_dafny "github.com/dafny-lang/DafnyRuntimeGo/v4/dafny"
    13  )
    14  
    15  var _ = os.Args
    16  var _ _dafny.Dummy__
    17  var _ m__System.Dummy__
    18  var _ m_Wrappers.Dummy__
    19  var _ m_Relations.Dummy__
    20  
    21  type Dummy__ struct{}
    22  
    23  // Definition of class Default__
    24  type Default__ struct {
    25  	dummy byte
    26  }
    27  
    28  func New_Default___() *Default__ {
    29  	_this := Default__{}
    30  
    31  	return &_this
    32  }
    33  
    34  type CompanionStruct_Default___ struct {
    35  }
    36  
    37  var Companion_Default___ = CompanionStruct_Default___{}
    38  
    39  func (_this *Default__) Equals(other *Default__) bool {
    40  	return _this == other
    41  }
    42  
    43  func (_this *Default__) EqualsGeneric(x interface{}) bool {
    44  	other, ok := x.(*Default__)
    45  	return ok && _this.Equals(other)
    46  }
    47  
    48  func (*Default__) String() string {
    49  	return "Seq_MergeSort.Default__"
    50  }
    51  func (_this *Default__) ParentTraits_() []*_dafny.TraitID {
    52  	return [](*_dafny.TraitID){}
    53  }
    54  
    55  var _ _dafny.TraitOffspring = &Default__{}
    56  
    57  func (_static *CompanionStruct_Default___) MergeSortBy(a _dafny.Sequence, lessThanOrEq func(interface{}, interface{}) bool) _dafny.Sequence {
    58  	if (_dafny.IntOfUint32((a).Cardinality())).Cmp(_dafny.One) <= 0 {
    59  		return a
    60  	} else {
    61  		var _0_splitIndex _dafny.Int = (_dafny.IntOfUint32((a).Cardinality())).DivBy(_dafny.IntOfInt64(2))
    62  		_ = _0_splitIndex
    63  		var _1_left _dafny.Sequence = (a).Take((_0_splitIndex).Uint32())
    64  		_ = _1_left
    65  		var _2_right _dafny.Sequence = (a).Drop((_0_splitIndex).Uint32())
    66  		_ = _2_right
    67  		var _3_leftSorted _dafny.Sequence = Companion_Default___.MergeSortBy(_1_left, lessThanOrEq)
    68  		_ = _3_leftSorted
    69  		var _4_rightSorted _dafny.Sequence = Companion_Default___.MergeSortBy(_2_right, lessThanOrEq)
    70  		_ = _4_rightSorted
    71  		return Companion_Default___.MergeSortedWith(_3_leftSorted, _4_rightSorted, func(coer0 func(interface{}, interface{}) bool) func(interface{}, interface{}) bool {
    72  			return func(arg0 interface{}, arg1 interface{}) bool {
    73  				return coer0(arg0, arg1)
    74  			}
    75  		}(lessThanOrEq))
    76  	}
    77  }
    78  func (_static *CompanionStruct_Default___) MergeSortedWith(left _dafny.Sequence, right _dafny.Sequence, lessThanOrEq func(interface{}, interface{}) bool) _dafny.Sequence {
    79  	var _0___accumulator _dafny.Sequence = _dafny.SeqOf()
    80  	_ = _0___accumulator
    81  	goto TAIL_CALL_START
    82  TAIL_CALL_START:
    83  	if (_dafny.IntOfUint32((left).Cardinality())).Sign() == 0 {
    84  		return _dafny.Companion_Sequence_.Concatenate(_0___accumulator, right)
    85  	} else if (_dafny.IntOfUint32((right).Cardinality())).Sign() == 0 {
    86  		return _dafny.Companion_Sequence_.Concatenate(_0___accumulator, left)
    87  	} else if (lessThanOrEq)((left).Select(0).(interface{}), (right).Select(0).(interface{})) {
    88  		_0___accumulator = _dafny.Companion_Sequence_.Concatenate(_0___accumulator, _dafny.SeqOf((left).Select(0).(interface{})))
    89  		var _in0 _dafny.Sequence = (left).Drop(1)
    90  		_ = _in0
    91  		var _in1 _dafny.Sequence = right
    92  		_ = _in1
    93  		var _in2 func(interface{}, interface{}) bool = lessThanOrEq
    94  		_ = _in2
    95  		left = _in0
    96  		right = _in1
    97  		lessThanOrEq = _in2
    98  		goto TAIL_CALL_START
    99  	} else {
   100  		_0___accumulator = _dafny.Companion_Sequence_.Concatenate(_0___accumulator, _dafny.SeqOf((right).Select(0).(interface{})))
   101  		var _in3 _dafny.Sequence = left
   102  		_ = _in3
   103  		var _in4 _dafny.Sequence = (right).Drop(1)
   104  		_ = _in4
   105  		var _in5 func(interface{}, interface{}) bool = lessThanOrEq
   106  		_ = _in5
   107  		left = _in3
   108  		right = _in4
   109  		lessThanOrEq = _in5
   110  		goto TAIL_CALL_START
   111  	}
   112  }
   113  
   114  // End of class Default__