Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

fix: make code in Cookbook compile #339

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions pages/cookbook/data-structures.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Following example emulates an array using a [`map<Int, V>{:tact}`][map] wrapped
import "@stdlib/deploy"; // for Deployable trait

struct Array {
map: map<Int as uint16, Int>; // array of Int values as a map of Ints to Ints,
// with serialization of its keys to uint16 to save space
length: Int = 0; // length of the array, defaults to 0
m: map<Int as uint16, Int>; // array of Int values as a map of Ints to Ints,
// with serialization of its keys to uint16 to save space
length: Int = 0; // length of the array, defaults to 0
}

// Compile-time constant upper bound for our map representing an array.
Expand Down Expand Up @@ -114,7 +114,7 @@ extends mutates fun deleteAll(self: Array) {

// Global static function for creating an empty Array
fun emptyArray(): Array {
return Array{map: emptyMap()}; // length defaults to 0
return Array{m: emptyMap(), length: 0}; // length defaults to 0
}

// Contract, with emulating an Array using the map
Expand Down Expand Up @@ -171,9 +171,9 @@ Following example emulates a stack using a [`map<Int, V>{:tact}`][map] wrapped i
import "@stdlib/deploy"; // for Deployable trait

struct Stack {
map: map<Int as uint16, Int>; // stack of Int values as a map of Ints to Ints,
// with serialization of its keys to uint16 to save space
length: Int = 0; // length of the stack, defaults to 0
m: map<Int as uint16, Int>; // stack of Int values as a map of Ints to Ints,
// with serialization of its keys to uint16 to save space
length: Int = 0; // length of the stack, defaults to 0
}

// Compile-time constant upper bound for our map representing an stack.
Expand Down Expand Up @@ -215,7 +215,7 @@ extends mutates fun deleteAll(self: Stack) {

// Global static function for creating an empty Stack
fun emptyStack(): Stack {
return Stack{map: emptyMap()}; // length defaults to 0
return Stack{m: emptyMap(), length: 0}; // length defaults to 0
}

contract MapAsStack with Deployable {
Expand Down Expand Up @@ -272,10 +272,10 @@ Following example emulates a circular buffer using a [`map<Int, V>{:tact}`][map]
import "@stdlib/deploy"; // for Deployable trait

struct CircularBuffer {
map: map<Int as uint8, Int>; // circular buffer of Int values as a map of Ints to Ints,
// with serialization of its keys to uint8 to save space
length: Int = 0; // length of the circular buffer, defaults to 0
start: Int = 0; // current index into the circular buffer, defaults to 0
m: map<Int as uint8, Int>; // circular buffer of Int values as a map of Ints to Ints,
// with serialization of its keys to uint8 to save space
length: Int = 0; // length of the circular buffer, defaults to 0
start: Int = 0; // current index into the circular buffer, defaults to 0
}

// Compile-time constant upper bound for our map representing a circular buffer.
Expand Down Expand Up @@ -324,7 +324,7 @@ extends mutates fun deleteAll(self: CircularBuffer) {

// Global static function for creating an empty CircularBuffer
fun emptyCircularBuffer(): CircularBuffer {
return CircularBuffer{map: emptyMap()}; // length and start default to 0
return CircularBuffer{m: emptyMap(), length: 0, start: 0}; // length and start default to 0
}

// This contract records the last 5 timestamps of when "timer" message was received
Expand Down
Loading