demo.lua 700 字节
Newer Older
Y
yihaoDeng 已提交
1 2 3 4 5 6 7 8
funcName = "test"

global =  {} 

function test_init()
  return global  
end

Y
yihaoDeng 已提交
9 10 11 12
function test_add(rows, ans, key)
  t = {}
  t["sum"] = 0.0
  t["num"] = 0
Y
yihaoDeng 已提交
13
  for i=1, #rows do
Y
yihaoDeng 已提交
14
    t["sum"] = t["sum"] + rows[i] * rows[i]  
Y
yihaoDeng 已提交
15
  end
Y
yihaoDeng 已提交
16 17 18 19 20 21 22 23 24 25 26
  t["num"] = #rows  


  if (ans[key] ~= nil)    
  then
    ans[key]["sum"] = ans[key]["sum"] + t["sum"]
    ans[key]["num"] = ans[key]["num"] + t["num"]
  else 
    ans[key] = t
  end
  
Y
yihaoDeng 已提交
27 28 29
  return ans; 
end

Y
yihaoDeng 已提交
30 31 32
function test_finalize(ans, key) 
  local ret = 0.0 

Y
yihaoDeng 已提交
33
  if (ans[key] ~= nil and ans[key]["num"] == 30000)    
Y
yihaoDeng 已提交
34 35 36 37 38 39 40 41 42
  then
    ret = ans[key]["sum"]/ans[key]["num"]
    ans[key]["sum"] = 0.0 
    ans[key]["num"] = 0
  else 
    ret = inf 
  end
  
  return ret, ans
Y
yihaoDeng 已提交
43
end