代码拉取完成,页面将自动刷新
package dsg
import (
"math"
)
/* 滑动数组表
* LList 负责分配空间; */
type LList struct
{
buf []Value
// 首节点索引
first int
// 最后一个节点下一个的索引
last int
}
func InitLList (nbuf int) * LList {
var ll LList
ll.buf = make ([]Value, nbuf + 1)
ll.first = 0
ll.last = 0
return &ll
}
func (ll * LList) Push (value Value) int {
nlast := real_mod (ll.last + 1, len(ll.buf))
if nlast == ll.first {
return -1
}
ll.buf[ll.last] = value
ll.last = nlast
return 0
}
func (ll * LList) Pop () (value Value) {
if ll.last == ll.first {
return nil
}
llast := real_mod (ll.last - 1, len(ll.buf))
value = ll.buf[llast]
ll.last = llast
return
}
func (ll * LList) PopFirst () (value Value) {
if ll.last == ll.first {
return nil
}
value = ll.buf[ll.first]
ll.first = real_mod (ll.first + 1, len(ll.buf))
return
}
func (ll * LList) GetLast () (value * Value) {
if ll.last == ll.first {
return nil
}
llast := real_mod (ll.last - 1, len(ll.buf))
return &(ll.buf[llast])
}
func (ll * LList) GetFirst () (value * Value) {
if ll.last == ll.first {
return nil
}
return &(ll.buf[ll.first])
}
func (ll * LList) Get (ind int) (value * Value) {
if ind < 0 || ind >= ll.GetN () {
return nil
}
rind := real_mod (ll.first + ind, len(ll.buf))
return &(ll.buf [rind])
}
func (ll * LList) GetN () int {
return real_mod (ll.last - ll.first, len(ll.buf))
}
func (ll * LList) Flush () {
ll.last = ll.first
}
func real_mod (a, b int) int {
if b < 0 {
b = int(math.Abs(float64(b)))
}
if a < 0 {
a += (- ((a + 1) / b) + 1) * b
} else {
a = a % b
}
return a
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。