1///|
2/// MaxStack dual-stack implementation
3/// Uses two stacks: one for data storage, one for tracking max values at each position
4///|
5/// MaxStack dual-stack implementation
6/// Uses two stacks: one for data storage, one for tracking max values at each position
7pub struct MaxStack[T] {
8  /// Data stack, stores actual elements
9  mut 
Array[T?]

Data stack, stores actual elements

data_stack
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[

type parameter T

T
?]
10 /// Max stack, stores the maximum value at each position 11 mut
Array[T?]

Max stack, stores the maximum value at each position

max_stack
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[

type parameter T

T
?]
12 /// Current stack size 13 mut
Int

Current stack size

size
:
Int
Int
14 /// Whether auto-resize is enabled 15
Bool

Whether auto-resize is enabled

auto_resize
:
Bool
Bool
16 /// Growth factor (used when auto_resize is true) 17
Double

Growth factor (used when auto_resize is true)

growth_factor
:
Double
Double
18} derive(
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
,
trait Show {
  output(Self, &Logger) -> Unit
  to_string(Self) -> String
}

Trait for types that can be converted to String

Show
)
19 20// ... Other type definitions remain unchanged 21///| 22/// Stack operation result type 23pub(all) enum StackResult[T] { 24 /// Operation succeeded, returns value 25
(T) -> StackResult[T]

Operation succeeded, returns value

Success
(

type parameter T

T
)
26 /// Stack is empty, operation failed 27
StackResult[T]

Stack is empty, operation failed

Empty
28 /// Stack is full, operation failed 29
StackResult[T]

Stack is full, operation failed

Full
30} 31 32///| 33/// Stack statistics 34pub struct StackStats { 35 /// Current number of elements 36
Int

Current number of elements

size
:
Int
Int
37 /// Stack capacity 38
Int

Stack capacity

capacity
:
Int
Int
39 /// Usage ratio 40
Double

Usage ratio

usage_ratio
:
Double
Double
41 /// Whether stack is empty 42
Bool

Whether stack is empty

is_empty
:
Bool
Bool
43 /// Whether stack is full 44
Bool

Whether stack is full

is_full
:
Bool
Bool
45} derive(
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
,
trait Show {
  output(Self, &Logger) -> Unit
  to_string(Self) -> String
}

Trait for types that can be converted to String

Show
)
46 47///| 48/// MaxStack configuration parameters 49pub struct MaxStackConfig { 50 /// Initial capacity 51
Int

Initial capacity

initial_capacity
:
Int
Int
52 /// Whether auto-resize is enabled 53
Bool

Whether auto-resize is enabled

auto_resize
:
Bool
Bool
54 /// Growth factor (used when auto_resize is true) 55
Double

Growth factor (used when auto_resize is true)

growth_factor
:
Double
Double
56} derive(
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
,
trait Show {
  output(Self, &Logger) -> Unit
  to_string(Self) -> String
}

Trait for types that can be converted to String

Show
)
57 58///| 59/// Stack state enumeration 60pub(all) enum StackState { 61 /// Empty stack state 62
StackState

Empty stack state

Empty
63 /// Normal state 64
StackState

Normal state

Normal
65 /// Near-full state (usage ratio > 80%) 66
StackState

Near-full state (usage ratio > 80%)

NearFull
67 /// Full state 68
StackState

Full state

Full
69} 70 71///| 72/// Serialization format 73pub struct SerializedMaxStack[T] { 74 /// Contents of data stack 75
Array[T]

Contents of data stack

data
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[

type parameter T

T
]
76 /// Contents of max stack 77
Array[T]

Contents of max stack

max_data
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[

type parameter T

T
]
78 /// Stack size 79
Int

Stack size

size
:
Int
Int
80 /// Capacity 81
Int

Capacity

capacity
:
Int
Int
82 /// Version number 83
Int

Version number

version
:
Int
Int
84} derive(
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
,
trait Show {
  output(Self, &Logger) -> Unit
  to_string(Self) -> String
}

Trait for types that can be converted to String

Show
)
85 86///| 87/// Stack iteration direction 88pub(all) enum IterationOrder { 89 /// From top to bottom (LIFO order) 90
IterationOrder

From top to bottom (LIFO order)

TopToBottom
91 /// From bottom to top 92
IterationOrder

From bottom to top

BottomToTop
93} 94 95///| 96/// Comparison operation result 97pub(all) enum CompareResult { 98 /// New element is new maximum 99
CompareResult

New element is new maximum

NewMax
100 /// New element equals current maximum 101
CompareResult

New element equals current maximum

EqualMax
102 /// New element is less than current maximum 103
CompareResult

New element is less than current maximum

NotMax
104} 105 106///| 107/// Stack snapshot (for debugging and analysis) 108pub struct StackSnapshot[T] { 109 /// Current data stack contents 110
Array[T]

Current data stack contents

data_stack
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[

type parameter T

T
]
111 /// Current max stack contents 112
Array[T]

Current max stack contents

max_stack
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[

type parameter T

T
]
113 /// Current size 114
Int

Current size

current_size
:
Int
Int
115 /// Current maximum value 116
T?

Current maximum value

current_max
:

type parameter T

T
?
117 /// Timestamp (identifies snapshot time) 118
Int

Timestamp (identifies snapshot time)

timestamp
:
Int
Int
119} derive(
trait Eq {
  op_equal(Self, Self) -> Bool
}

Trait for types whose elements can test for equality

Eq
,
trait Show {
  output(Self, &Logger) -> Unit
  to_string(Self) -> String
}

Trait for types that can be converted to String

Show
)
120