mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-22 15:30:06 +00:00
Added another example script 'compare.comso'
- This stresses the table implementation as well as cosmoV_equals
This commit is contained in:
parent
6bc4ec6b04
commit
da85d640ce
40
examples/compare.cosmo
Normal file
40
examples/compare.cosmo
Normal file
@ -0,0 +1,40 @@
|
||||
var strtable = []
|
||||
var strLen = 4 // length of all strings to generate
|
||||
var AByte = "A":byte() // grabs the ascii value of 'A'
|
||||
|
||||
proto stringBuilder
|
||||
function __init(self, length)
|
||||
self.len = length
|
||||
end
|
||||
|
||||
// we are the iterator object lol
|
||||
function __iter(self)
|
||||
self.x = 0
|
||||
return self
|
||||
end
|
||||
|
||||
function __next(self)
|
||||
var x = self.x++
|
||||
|
||||
// if we've generated all the possible strings, return nil ending the loop
|
||||
if x >= 26 ^ self.len then
|
||||
return nil
|
||||
end
|
||||
|
||||
// generate the string
|
||||
var str = ""
|
||||
for (var i = 0; i < self.len; i++) do
|
||||
str = string.char(AByte + (x % 26)) .. str
|
||||
|
||||
x = math.floor(x / 26)
|
||||
end
|
||||
|
||||
return str
|
||||
end
|
||||
end
|
||||
|
||||
// generate a bunch of strings & populate the table
|
||||
print("generating " .. 26 ^ strLen .. " strings...")
|
||||
for str in stringBuilder(strLen) do
|
||||
strtable[str] = true
|
||||
end
|
Loading…
Reference in New Issue
Block a user