22 lines
579 B
Mojo
22 lines
579 B
Mojo
struct ScanBuffer:
|
|
var samples: List[Int]
|
|
|
|
def __init__(out self, var samples: List[Int]):
|
|
self.samples = samples^
|
|
|
|
def push(mut self, t: Int):
|
|
self.samples.append(t)
|
|
|
|
def size(self) -> Int:
|
|
return len(self.samples)
|
|
|
|
|
|
def main():
|
|
var original: List[Int] = [1, 2, 3]
|
|
var snapshot = ScanBuffer(original^)
|
|
# The black-box recorder keeps an independent copy so later edits don't leak in.
|
|
var working = snapshot.copy()
|
|
working.push(99)
|
|
print("snapshot size:", snapshot.size())
|
|
print("working size:", working.size())
|