Code: Select all
f:=[]
loop 1000
{
t:=random(1,100)
if f[t]
f[t]++
else if t>f.maxindex() or t<f.minindex()
f[t]:=1
}
Code: Select all
f:=[]
loop 1000
{
t:=random(1,100)
if f[t]
f[t]++
else if t>f.maxindex() or t<f.minindex()
f[t]:=1
}
Code: Select all
f:=c.new()
loop 1000
f[random(1,100)]++
class c extends map {
__item[i] => this.has(i) ? base[i] : 0
}
Code: Select all
f:=map()
min := 100
max := 1
loop 1000
{
t:=random(1,100)
if f.has(t)
f[t]++,
else if (t>max && max:=t) or (t<min && min:=t)
f[t]:=1
}
Code: Select all
f:=map()
min := 100
max := 0
loop 1000
{
t:=random(1,100)
if f.has(t)
f[t]++,
else if t>max or t<min
f[t]:=1, max:=max(t,max), min:=min(t,min)
}
Code: Select all
max(f){
for i in f
max:=i
return max
}
min(f){
for i in f
return i
}
Code: Select all
f:=c.new(100)
loop 1000
{
t:=random(1,100)
if f.has(t)
f[t]++
else if t>f.max or t<f.min
f[t]:=1
}
class c extends map {
__item[i] {
set => (this.minmax(i), base[i] := value)
}
max := 0
__new(max) => this.min := max
minmax(i) {
this.max:=max(i,this.max), this.min:=min(i,this.min)
}
}
probably because Maps are supposed to be associative array dictionary types, and therefore its weird to query min/max integer keys when you are expecting random key names
Regarding performance, my test results are the opposite of yours.
loop 1000000
V2 V100 0.550465S
V2 V108 0.903593S
I can't imagine why you think this function will be faster than the built-in functions.
minmax(i) {
this.max:=max(i,this.max), this.min:=min(i,this.min)
}
Code: Select all
f:=map()
min := 100
max := 0
loop 1000
{
t:=random(1,100)
if f.has(t)
f[t]++,
else if t>max or t<min
f[t]:=1, max:=max(t,max), min:=min(t,min)
}
f.min := min
f.max := max
No. I had simply copied @arcticir's snippet and executed it with the 1.1.32.00 interpreter ("implement this V1 code" implying v1). I failed to account for the fact that the piece of code was, indeed, not v1-compliant (t:=random(1,100)). Unfortunately, the interpreter (through no fault of its own), too, failed to alert me. What had happened is that Random.ahk, part of a library I had been testing these past couple of days, was auto-included from my AutoHotkey Lib folder. The function performs extra checks in addition to having other user-defined functions as dependencies, hence the atrocious performance.
Ok, but it would be then also weird to build a class with functions that extends Map or Array, right?
i think the idea is what Helgef said: Min and MaxIndex are not very useful most of the time, but if you need them for very specific edge cases, then you can easily extend the class to provide them yourself, as he showed. normal arrays start at 1 and you keep pushing new items, so maxIndex = .Length, thats the most common use case
Users browsing this forum: Hansielein and 70 guests