2020-12-05 23:58:56 +00:00
|
|
|
proto Vector
|
2020-11-20 21:10:49 +00:00
|
|
|
function __init(self)
|
2021-01-09 05:07:44 +00:00
|
|
|
self.vector = []
|
2020-11-20 21:10:49 +00:00
|
|
|
self.x = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
function push(self, val)
|
2020-11-20 21:32:12 +00:00
|
|
|
self.vector[self.x++] = val
|
2020-11-20 21:10:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function pop(self)
|
2020-11-20 21:32:12 +00:00
|
|
|
return self.vector[--self.x]
|
2020-11-20 21:10:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function __index(self, key)
|
2020-11-20 21:32:12 +00:00
|
|
|
return self.vector[key]
|
2020-11-20 21:10:49 +00:00
|
|
|
end
|
2020-12-18 01:44:04 +00:00
|
|
|
|
|
|
|
function __iter(self)
|
2021-01-12 23:49:16 +00:00
|
|
|
// you don't *have* to make a new object, i just wanted to show off anonymous functions
|
|
|
|
return {__next = (function(self)
|
|
|
|
return self.vector[self.iterIndex++]
|
|
|
|
end),
|
|
|
|
iterIndex = 0,
|
|
|
|
vector = self.vector
|
|
|
|
}
|
2020-12-18 01:44:04 +00:00
|
|
|
end
|
2020-11-20 21:10:49 +00:00
|
|
|
end
|
|
|
|
|
2020-11-20 21:32:12 +00:00
|
|
|
var vector = Vector()
|
2020-11-20 21:10:49 +00:00
|
|
|
|
2020-11-20 21:32:12 +00:00
|
|
|
for (var i = 0; i < 100000; i++) do
|
2021-01-12 23:49:16 +00:00
|
|
|
vector:push(i)
|
2020-11-20 21:10:49 +00:00
|
|
|
end
|
|
|
|
|
2021-01-12 23:49:16 +00:00
|
|
|
local total = 0
|
2020-12-18 01:44:04 +00:00
|
|
|
for i in vector do
|
|
|
|
print(i)
|
2020-11-20 21:10:49 +00:00
|
|
|
end
|