diff --git a/build/StarcoinFramework/BuildInfo.yaml b/build/StarcoinFramework/BuildInfo.yaml index 013c40fd..3e6d9bf5 100644 --- a/build/StarcoinFramework/BuildInfo.yaml +++ b/build/StarcoinFramework/BuildInfo.yaml @@ -171,9 +171,6 @@ compiled_package_info: ? address: "0x00000000000000000000000000000001" name: RewardConfig : StarcoinFramework - ? address: "0x00000000000000000000000000000001" - name: Ring - : StarcoinFramework ? address: "0x00000000000000000000000000000001" name: SIP_2 : StarcoinFramework @@ -261,7 +258,7 @@ compiled_package_info: ? address: "0x00000000000000000000000000000001" name: YieldFarmingV2 : StarcoinFramework - source_digest: F39F5364AE53D568F6DE697F20438F49769B5D07FDB6D7231ED2F8262053CE66 + source_digest: 32826A6EC6BBC9EA88FE5A7FAFAA167756EDA62C7FD903B59751BCF002F09AE4 build_flags: dev_mode: false test_mode: false diff --git a/build/StarcoinFramework/bytecode_modules/Ring.mv b/build/StarcoinFramework/bytecode_modules/Ring.mv deleted file mode 100644 index d14fabef..00000000 Binary files a/build/StarcoinFramework/bytecode_modules/Ring.mv and /dev/null differ diff --git a/build/StarcoinFramework/docs/README.md b/build/StarcoinFramework/docs/README.md index d15b13b8..2bd3c30e 100644 --- a/build/StarcoinFramework/docs/README.md +++ b/build/StarcoinFramework/docs/README.md @@ -67,7 +67,6 @@ This is the root document for the Move StarcoinFramework module documentation. T - [`0x1::PriceOracleAggregator`](Oracle.md#0x1_PriceOracleAggregator) - [`0x1::PriceOracleScripts`](Oracle.md#0x1_PriceOracleScripts) - [`0x1::RewardConfig`](RewardConfig.md#0x1_RewardConfig) -- [`0x1::Ring`](Ring.md#0x1_Ring) - [`0x1::SIP_2`](SIPs.md#0x1_SIP_2) - [`0x1::SIP_3`](SIPs.md#0x1_SIP_3) - [`0x1::STC`](STC.md#0x1_STC) diff --git a/build/StarcoinFramework/docs/Ring.md b/build/StarcoinFramework/docs/Ring.md deleted file mode 100644 index fca175fb..00000000 --- a/build/StarcoinFramework/docs/Ring.md +++ /dev/null @@ -1,437 +0,0 @@ - - - -# Module `0x1::Ring` - -A ring-shaped container that can hold any type, indexed from 0 -The capacity is fixed at creation time, and the accessible index is constantly growing - - -- [Struct `Ring`](#0x1_Ring_Ring) -- [Constants](#@Constants_0) -- [Function `create_with_capacity`](#0x1_Ring_create_with_capacity) -- [Function `is_full`](#0x1_Ring_is_full) -- [Function `capacity`](#0x1_Ring_capacity) -- [Function `push`](#0x1_Ring_push) -- [Function `borrow`](#0x1_Ring_borrow) -- [Function `borrow_mut`](#0x1_Ring_borrow_mut) -- [Function `index_of`](#0x1_Ring_index_of) -- [Function `destroy`](#0x1_Ring_destroy) - - -
use 0x1::Errors;
-use 0x1::Option;
-use 0x1::Vector;
-
- - - - - -## Struct `Ring` - - - -
struct Ring<Element> has store
-
- - - -
-Fields - - -
-
-data: vector<Option::Option<Element>> -
-
- -
-
-insertion_index: u64 -
-
- -
-
-external_index: u64 -
-
- -
-
- - -
- - - -## Constants - - - - -The index into the vector is out of bounds - - -
const ERROR_RING_INDEX_OUT_OF_BOUNDS: u64 = 101;
-
- - - - - -## Function `create_with_capacity` - -Create a Ring with capacity. - - -
public fun create_with_capacity<Element>(len: u64): Ring::Ring<Element>
-
- - - -
-Implementation - - -
public fun create_with_capacity<Element>( len: u64 ):Ring<Element>{
-    let data = Vector::empty<Option::Option<Element>>();
-    let i = 0;
-    while(i < len){
-        Vector::push_back(&mut data , Option::none<Element>());
-        i = i + 1;
-    };
-    Ring {
-        data             : data,
-        insertion_index  : 0,
-        external_index   : 0,
-    }
-}
-
- - - -
- -
-Specification - - - -
pragma intrinsic = true;
-
- - - -
- - - -## Function `is_full` - -is Ring full - - -
public fun is_full<Element>(r: &Ring::Ring<Element>): bool
-
- - - -
-Implementation - - -
public fun is_full<Element>(r: &Ring<Element>):bool{
-    Option::is_some(Vector::borrow(&r.data, r.insertion_index))
-}
-
- - - -
- -
-Specification - - - -
pragma intrinsic = true;
-
- - - -
- - - -## Function `capacity` - -Return the capacity of the Ring. - - -
public fun capacity<Element>(r: &Ring::Ring<Element>): u64
-
- - - -
-Implementation - - -
public fun capacity<Element>(r: &Ring<Element>): u64{
-    Vector::length( &r.data )
-}
-
- - - -
- -
-Specification - - - -
pragma intrinsic = true;
-
- - - -
- - - -## Function `push` - -Add element e to the insertion_index of the Ring r. - - -
public fun push<Element>(r: &mut Ring::Ring<Element>, e: Element): Option::Option<Element>
-
- - - -
-Implementation - - -
public fun push<Element> (r: &mut Ring<Element> , e: Element):Option::Option<Element>{
-    let op_e = Vector::borrow_mut<Option::Option<Element>>(&mut r.data, r.insertion_index);
-    let res = if(  Option::is_none<Element>(op_e) ){
-        Option::fill( op_e, e);
-        Option::none<Element>()
-    }else{
-       Option::some<Element>( Option::swap( op_e, e) )
-    };
-    r.insertion_index = ( r.insertion_index + 1 ) % Vector::length(&r.data);
-    r.external_index = r.external_index + 1;
-    res
-}
-
- - - -
- -
-Specification - - - -
pragma intrinsic = true;
-
- - - -
- - - -## Function `borrow` - -Return a reference to the ith element in the Ring r. - - -
public fun borrow<Element>(r: &Ring::Ring<Element>, i: u64): &Option::Option<Element>
-
- - - -
-Implementation - - -
public fun borrow<Element>(r:& Ring<Element>, i: u64):&Option::Option<Element>{
-    let len = capacity<Element>(r);
-    if( r.external_index > len - 1) {
-        assert!( i >= r.external_index - len && i < r.external_index , Errors::invalid_argument(ERROR_RING_INDEX_OUT_OF_BOUNDS));
-        Vector::borrow(&r.data, i % len)
-    }else {
-        assert!( i < len , Errors::invalid_argument(ERROR_RING_INDEX_OUT_OF_BOUNDS));
-        Vector::borrow(&r.data, i )
-    }
-}
-
- - - -
- -
-Specification - - - -
pragma intrinsic = true;
-
- - - -
- - - -## Function `borrow_mut` - -Return a mutable reference to the ith element in the Ring r. - - -
public fun borrow_mut<Element>(r: &mut Ring::Ring<Element>, i: u64): &mut Option::Option<Element>
-
- - - -
-Implementation - - -
public fun borrow_mut<Element>(r: &mut Ring<Element>, i: u64):&mut Option::Option<Element>{
-    let len = capacity<Element>(r);
-    if( r.external_index > len - 1) {
-        assert!( i >= r.external_index - len && i < r.external_index , Errors::invalid_argument(ERROR_RING_INDEX_OUT_OF_BOUNDS));
-        Vector::borrow_mut(&mut r.data, i % len)
-    }else {
-        assert!( i < len , Errors::invalid_argument(ERROR_RING_INDEX_OUT_OF_BOUNDS));
-        Vector::borrow_mut(&mut r.data, i )
-    }
-
-}
-
- - - -
- -
-Specification - - - -
pragma intrinsic = true;
-
- - - -
- - - -## Function `index_of` - -Return Option::Option<u64> if e is in the Ring r at index i. -Otherwise, returns Option::none<u64>. - - -
public fun index_of<Element>(r: &Ring::Ring<Element>, e: &Element): Option::Option<u64>
-
- - - -
-Implementation - - -
public fun index_of<Element>(r: &Ring<Element>, e: &Element):Option::Option<u64>{
-    let i = 0;
-    let len = capacity<Element>(r);
-    while ( i < len ) {
-        if ( Option::borrow(Vector::borrow( &r.data, i )) == e) return Option::some(i + r.external_index - len);
-        i = i + 1;
-    };
-    Option::none<u64>()
-}
-
- - - -
- -
-Specification - - - -
pragma intrinsic = true;
-
- - - -
- - - -## Function `destroy` - -Destroy the Ring r. -Returns the vector saved by ring - - -
public fun destroy<Element>(r: Ring::Ring<Element>): vector<Element>
-
- - - -
-Implementation - - -
public fun destroy<Element>(r: Ring<Element>):vector<Element>{
-    let Ring {
-        data            : data ,
-        insertion_index : _,
-        external_index  : _,
-    } = r ;
-    let len = Vector::length(&data);
-    let i = 0;
-    let vec = Vector::empty<Element>();
-    while ( i < len ) {
-        let op_e = Vector::pop_back( &mut data );
-        if ( Option::is_some(&op_e) ) {
-            Vector::push_back(&mut vec, Option::destroy_some(op_e))
-        }else {
-           Option::destroy_none(op_e)
-        };
-        i = i + 1;
-    };
-    Vector::destroy_empty(data);
-    vec
-}
-
- - - -
- -
-Specification - - - -
pragma intrinsic = true;
-
- - - -
diff --git a/build/StarcoinFramework/source_maps/Ring.mvsm b/build/StarcoinFramework/source_maps/Ring.mvsm deleted file mode 100644 index 2e9de601..00000000 Binary files a/build/StarcoinFramework/source_maps/Ring.mvsm and /dev/null differ diff --git a/integration-tests/ring/rind_set.exp b/integration-tests/ring/rind_set.exp deleted file mode 100644 index 8d6ea7e6..00000000 --- a/integration-tests/ring/rind_set.exp +++ /dev/null @@ -1,9 +0,0 @@ -processed 3 tasks - -task 2 'run'. lines 5-28: -{ - "gas_used": 504308, - "status": { - "Keep": "Executed" - } -} diff --git a/integration-tests/ring/rind_set.move b/integration-tests/ring/rind_set.move deleted file mode 100644 index b60e12c6..00000000 --- a/integration-tests/ring/rind_set.move +++ /dev/null @@ -1,28 +0,0 @@ -//# init -n test - -//# faucet --addr alice --amount 100000000000000000 - -//# run --signers alice -script { -use StarcoinFramework::Ring; -use StarcoinFramework::Option; - -fun main() { - let ring = Ring::create_with_capacity(5); - - assert!(Ring::capacity(&ring) == 5, 1001); - let i = 0; - while(i < 6){ - Ring::push(&mut ring , i); - i = i + 1; - }; - - assert!(*Option::borrow(Ring::borrow(&ring, 5)) == 5, 1002); - assert!(*Option::borrow(Ring::borrow(&ring, 1)) == 1, 1003); - assert!(*Option::borrow(Ring::borrow(&ring, 2)) == 2, 1004); - assert!(*Option::borrow(Ring::borrow(&ring, 3)) == 3, 1005); - assert!(*Option::borrow(Ring::borrow(&ring, 4)) == 4, 1006); - - _ = Ring::destroy( ring ); -} -} diff --git a/integration-tests/ring/ring_add.exp b/integration-tests/ring/ring_add.exp deleted file mode 100644 index f81c5baa..00000000 --- a/integration-tests/ring/ring_add.exp +++ /dev/null @@ -1,9 +0,0 @@ -processed 3 tasks - -task 2 'run'. lines 5-15: -{ - "gas_used": 161829, - "status": { - "Keep": "Executed" - } -} diff --git a/integration-tests/ring/ring_add.move b/integration-tests/ring/ring_add.move deleted file mode 100644 index 2500f352..00000000 --- a/integration-tests/ring/ring_add.move +++ /dev/null @@ -1,15 +0,0 @@ -//# init -n test - -//# faucet --addr alice --amount 100000000000000000 - -//# run --signers alice -script { -use StarcoinFramework::Ring; -fun main() { - let ring = Ring::create_with_capacity(5); - - assert!(Ring::capacity(&ring) == 5, 1001); - - _ = Ring::destroy( ring ); -} -} diff --git a/integration-tests/ring/ring_borrow.exp b/integration-tests/ring/ring_borrow.exp deleted file mode 100644 index c4c2df49..00000000 --- a/integration-tests/ring/ring_borrow.exp +++ /dev/null @@ -1,9 +0,0 @@ -processed 3 tasks - -task 2 'run'. lines 5-28: -{ - "gas_used": 463521, - "status": { - "Keep": "Executed" - } -} diff --git a/integration-tests/ring/ring_borrow.move b/integration-tests/ring/ring_borrow.move deleted file mode 100644 index 79f051d7..00000000 --- a/integration-tests/ring/ring_borrow.move +++ /dev/null @@ -1,28 +0,0 @@ -//# init -n test - -//# faucet --addr alice --amount 100000000000000000 - -//# run --signers alice -script { -use StarcoinFramework::Ring; -use StarcoinFramework::Option; - -fun main() { - let ring = Ring::create_with_capacity(5); - - assert!(Ring::capacity(&ring) == 5, 1001); - let i = 0; - while(i < 5){ - Ring::push(&mut ring , i); - i = i + 1; - }; - - assert!(*Option::borrow(Ring::borrow(&ring, 0)) == 0, 1002); - assert!(*Option::borrow(Ring::borrow(&ring, 1)) == 1, 1003); - assert!(*Option::borrow(Ring::borrow(&ring, 2)) == 2, 1004); - assert!(*Option::borrow(Ring::borrow(&ring, 3)) == 3, 1005); - assert!(*Option::borrow(Ring::borrow(&ring, 4)) == 4, 1006); - - _ = Ring::destroy( ring ); -} -} diff --git a/integration-tests/ring/ring_borrow_mut.exp b/integration-tests/ring/ring_borrow_mut.exp deleted file mode 100644 index 627c6219..00000000 --- a/integration-tests/ring/ring_borrow_mut.exp +++ /dev/null @@ -1,9 +0,0 @@ -processed 3 tasks - -task 2 'run'. lines 5-33: -{ - "gas_used": 453800, - "status": { - "Keep": "Executed" - } -} diff --git a/integration-tests/ring/ring_borrow_mut.move b/integration-tests/ring/ring_borrow_mut.move deleted file mode 100644 index 78904b97..00000000 --- a/integration-tests/ring/ring_borrow_mut.move +++ /dev/null @@ -1,33 +0,0 @@ -//# init -n test - -//# faucet --addr alice --amount 100000000000000000 - -//# run --signers alice -script { -use StarcoinFramework::Ring; -use StarcoinFramework::Option; - -fun main() { - let ring = Ring::create_with_capacity(5); - - assert!(Ring::capacity(&ring) == 5, 1001); - let i = 0; - while(i < 5){ - let op_e = Ring::borrow_mut(&mut ring, i) ; - if( Option::is_some(op_e) ){ - Option::swap( op_e , i); - }else{ - Option::fill( op_e , i); - }; - i = i + 1; - }; - - assert!(*Option::borrow(Ring::borrow(&ring, 0)) == 0, 1002); - assert!(*Option::borrow(Ring::borrow(&ring, 1)) == 1, 1003); - assert!(*Option::borrow(Ring::borrow(&ring, 2)) == 2, 1004); - assert!(*Option::borrow(Ring::borrow(&ring, 3)) == 3, 1005); - assert!(*Option::borrow(Ring::borrow(&ring, 4)) == 4, 1006); - - _ = Ring::destroy( ring ); -} -} diff --git a/integration-tests/ring/ring_index_of.exp b/integration-tests/ring/ring_index_of.exp deleted file mode 100644 index 7ca95309..00000000 --- a/integration-tests/ring/ring_index_of.exp +++ /dev/null @@ -1,53 +0,0 @@ -processed 6 tasks - -task 2 'run'. lines 5-33: -{ - "gas_used": 1051801, - "status": { - "Keep": "Executed" - } -} - -task 3 'run'. lines 35-68: -{ - "gas_used": 1072590, - "status": { - "Keep": "Executed" - } -} - -task 4 'run'. lines 71-93: -{ - "gas_used": 414425, - "status": { - "Keep": { - "MoveAbort": [ - { - "Module": { - "address": "0x00000000000000000000000000000001", - "name": "Ring" - } - }, - 25863 - ] - } - } -} - -task 5 'run'. lines 96-118: -{ - "gas_used": 414507, - "status": { - "Keep": { - "MoveAbort": [ - { - "Module": { - "address": "0x00000000000000000000000000000001", - "name": "Ring" - } - }, - 25863 - ] - } - } -} diff --git a/integration-tests/ring/ring_index_of.move b/integration-tests/ring/ring_index_of.move deleted file mode 100644 index 97d04035..00000000 --- a/integration-tests/ring/ring_index_of.move +++ /dev/null @@ -1,118 +0,0 @@ -//# init -n test - -//# faucet --addr alice --amount 100000000000000000 - -//# run --signers alice -script { -use StarcoinFramework::Ring; -use StarcoinFramework::Option; - -fun main() { - let ring = Ring::create_with_capacity(5); - - assert!(Ring::capacity(&ring) == 5, 1001); - let i = 0; - while(i < 10){ - Ring::push(&mut ring , i + 1); - i = i + 1; - }; - // Ring : [6, 7, 8, 9, 10] - // index: 5, 6, 7, 8, 9 - assert!(Option::is_none( &Ring::index_of(&ring, &20)) , 1002 ); - - assert!(*Option::borrow( &Ring::index_of(&ring, &6)) == 5, 1003 ); - assert!(*Option::borrow( &Ring::index_of(&ring, &7)) == 6, 1004 ); - assert!(*Option::borrow( &Ring::index_of(&ring, &8)) == 7, 1005 ); - assert!(*Option::borrow( &Ring::index_of(&ring, &9)) == 8, 1006 ); - assert!(*Option::borrow( &Ring::index_of(&ring, &10)) == 9, 1007 ); - - _ = Ring::destroy( ring ); - -} -} -//check Executed - -//# run --signers alice -script { -use StarcoinFramework::Ring; -use StarcoinFramework::Option; - -fun find_and_use_index() { - let ring = Ring::create_with_capacity(5); - - assert!(Ring::capacity(&ring) == 5, 1001); - let i = 0; - while(i < 10){ - Ring::push(&mut ring , i + 1); - i = i + 1; - }; - - // Ring : [6, 7, 8, 9, 10] - // index: 5, 6, 7, 8, 9 - assert!(*Option::borrow( &Ring::index_of(&ring, &6)) == 5, 1003 ); - assert!(*Option::borrow( &Ring::index_of(&ring, &7)) == 6, 1004 ); - assert!(*Option::borrow( &Ring::index_of(&ring, &8)) == 7, 1005 ); - assert!(*Option::borrow( &Ring::index_of(&ring, &9)) == 8, 1006 ); - assert!(*Option::borrow( &Ring::index_of(&ring, &10)) == 9, 1007 ); - - assert!(*Option::borrow( Ring::borrow(&ring, 5)) == 6 , 1010); - assert!(*Option::borrow( Ring::borrow(&ring, 6)) == 7 , 1011); - assert!(*Option::borrow( Ring::borrow(&ring, 7)) == 8 , 1012); - assert!(*Option::borrow( Ring::borrow(&ring, 8)) == 9 , 1013); - assert!(*Option::borrow( Ring::borrow(&ring, 9)) == 10 , 1014); - - _ = Ring::destroy( ring ); - -} -} -//check Executed - - -//# run --signers alice -script { -use StarcoinFramework::Ring; -use StarcoinFramework::Option; - -fun exceed_the_lower_limit() { - let ring = Ring::create_with_capacity(5); - - assert!(Ring::capacity(&ring) == 5, 1001); - let i = 0; - while(i < 10){ - Ring::push(&mut ring , i + 1); - i = i + 1; - }; - - // Ring : [6, 7, 8, 9, 10] - // index: 5, 6, 7, 8, 9 - *Option::borrow( Ring::borrow(&ring, 4)); - _ = Ring::destroy( ring ); - -} -} -//check MoveAbort 25863 - - -//# run --signers alice -script { -use StarcoinFramework::Ring; -use StarcoinFramework::Option; - -fun exceed_the_upper_limit() { - let ring = Ring::create_with_capacity(5); - - assert!(Ring::capacity(&ring) == 5, 1001); - let i = 0; - while(i < 10){ - Ring::push(&mut ring , i + 1); - i = i + 1; - }; - - // Ring : [6, 7, 8, 9, 10] - // index: 5, 6, 7, 8, 9 - *Option::borrow( Ring::borrow(&ring, 10)); - _ = Ring::destroy( ring ); - -} -} -//check MoveAbort 25863 \ No newline at end of file diff --git a/sources/Ring.move b/sources/Ring.move deleted file mode 100644 index b60aa39f..00000000 --- a/sources/Ring.move +++ /dev/null @@ -1,154 +0,0 @@ -address StarcoinFramework { - -/// A ring-shaped container that can hold any type, indexed from 0 -/// The capacity is fixed at creation time, and the accessible index is constantly growing -module Ring { - - use StarcoinFramework::Vector; - use StarcoinFramework::Option; - use StarcoinFramework::Errors; - - - /// The index into the vector is out of bounds - const ERROR_RING_INDEX_OUT_OF_BOUNDS:u64 = 101; - - struct Ring has store{ - data : vector>, - insertion_index : u64, - external_index : u64 - } - - /// Create a Ring with capacity. - public fun create_with_capacity( len: u64 ):Ring{ - let data = Vector::empty>(); - let i = 0; - while(i < len){ - Vector::push_back(&mut data , Option::none()); - i = i + 1; - }; - Ring { - data : data, - insertion_index : 0, - external_index : 0, - } - } - - spec create_with_capacity{ - pragma intrinsic = true; - } - - ///is Ring full - public fun is_full(r: &Ring):bool{ - Option::is_some(Vector::borrow(&r.data, r.insertion_index)) - } - - spec is_full{ - pragma intrinsic = true; - } - - ///Return the capacity of the Ring. - public fun capacity(r: &Ring): u64{ - Vector::length( &r.data ) - } - - spec capacity{ - pragma intrinsic = true; - } - - /// Add element `e` to the insertion_index of the Ring `r`. - public fun push (r: &mut Ring , e: Element):Option::Option{ - let op_e = Vector::borrow_mut>(&mut r.data, r.insertion_index); - let res = if( Option::is_none(op_e) ){ - Option::fill( op_e, e); - Option::none() - }else{ - Option::some( Option::swap( op_e, e) ) - }; - r.insertion_index = ( r.insertion_index + 1 ) % Vector::length(&r.data); - r.external_index = r.external_index + 1; - res - } - - spec push{ - pragma intrinsic = true; - } - - /// Return a reference to the `i`th element in the Ring `r`. - public fun borrow(r:& Ring, i: u64):&Option::Option{ - let len = capacity(r); - if( r.external_index > len - 1) { - assert!( i >= r.external_index - len && i < r.external_index , Errors::invalid_argument(ERROR_RING_INDEX_OUT_OF_BOUNDS)); - Vector::borrow(&r.data, i % len) - }else { - assert!( i < len , Errors::invalid_argument(ERROR_RING_INDEX_OUT_OF_BOUNDS)); - Vector::borrow(&r.data, i ) - } - } - - spec borrow{ - pragma intrinsic = true; - } - - /// Return a mutable reference to the `i`th element in the Ring `r`. - public fun borrow_mut(r: &mut Ring, i: u64):&mut Option::Option{ - let len = capacity(r); - if( r.external_index > len - 1) { - assert!( i >= r.external_index - len && i < r.external_index , Errors::invalid_argument(ERROR_RING_INDEX_OUT_OF_BOUNDS)); - Vector::borrow_mut(&mut r.data, i % len) - }else { - assert!( i < len , Errors::invalid_argument(ERROR_RING_INDEX_OUT_OF_BOUNDS)); - Vector::borrow_mut(&mut r.data, i ) - } - - } - - spec borrow_mut{ - pragma intrinsic = true; - } - - - /// Return `Option::Option` if `e` is in the Ring `r` at index `i`. - /// Otherwise, returns `Option::none`. - public fun index_of(r: &Ring, e: &Element):Option::Option{ - let i = 0; - let len = capacity(r); - while ( i < len ) { - if ( Option::borrow(Vector::borrow( &r.data, i )) == e) return Option::some(i + r.external_index - len); - i = i + 1; - }; - Option::none() - } - - spec index_of{ - pragma intrinsic = true; - } - - /// Destroy the Ring `r`. - /// Returns the vector saved by ring - public fun destroy(r: Ring):vector{ - let Ring { - data : data , - insertion_index : _, - external_index : _, - } = r ; - let len = Vector::length(&data); - let i = 0; - let vec = Vector::empty(); - while ( i < len ) { - let op_e = Vector::pop_back( &mut data ); - if ( Option::is_some(&op_e) ) { - Vector::push_back(&mut vec, Option::destroy_some(op_e)) - }else { - Option::destroy_none(op_e) - }; - i = i + 1; - }; - Vector::destroy_empty(data); - vec - } - - spec destroy{ - pragma intrinsic = true; - } -} -} \ No newline at end of file