Feed Data Structure


👉 BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member 👈

 

Tweet monkey-x code-archives miscellaneous
BlitzCoder

It's a FIFO stack with a limit. You basically push items to it and it and the newest one will be on top. It has a fixed size though so everything that's pushed out will be lost.

Author: Shinkiro1

Strict

Class Feed<T>

Method New(size:Int)
data = New T[size]
End

Method Push:Void(val:T)
For Local i:Int = count To 1 Step -1
data[i] = data[i-1]
Next
data[0] = val
count += 1
count = Min(count, data.Length-1)
End

Method Get:T(i:Int)
Return data[i]
End

Method Length:Int() Property
Return count+1
End

Private
Field data:T[]
Field count:Int
End

Reply To Topic (minimum 10 characters)

Please log in to reply