2020-12-05 23:58:56 +00:00
|
|
|
proto Vector
|
2020-11-20 21:10:49 +00:00
|
|
|
function __init(self)
|
2020-11-20 21:32:12 +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)
|
|
|
|
self.iterIndex = 0
|
|
|
|
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
|
|
|
function __next(self)
|
|
|
|
if self.iterIndex > self.x then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return vector[self.iterIndex++]
|
|
|
|
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
|
|
|
|
vector.push(i)
|
2020-11-20 21:10:49 +00:00
|
|
|
end
|
|
|
|
|
2020-12-18 01:44:04 +00:00
|
|
|
for i in vector do
|
|
|
|
print(i)
|
2020-11-20 21:10:49 +00:00
|
|
|
end
|