Skip to content

Instantly share code, notes, and snippets.

@matthewcrews
Created May 27, 2022 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewcrews/8e9f290e3aad6b0c6efb2bdc493b6c5b to your computer and use it in GitHub Desktop.
Save matthewcrews/8e9f290e3aad6b0c6efb2bdc493b6c5b to your computer and use it in GitHub Desktop.
[<Struct;IsByRefLike>]
type StackStack<'T>(values: Span<'T>) =
[<DefaultValue>] val mutable private Count : int
member s.Push v =
if s.Count < values.Length then
values[s.Count] <- v
s.Count <- s.Count + 1
else
failwith "Exceeded capacity of StackStack"
member s.Pop () =
if s.Count > 0 then
s.Count <- s.Count - 1
values[s.Count]
else
failwith "Empty StackStack"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment