Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Doc] Added description for the boost context factory
[simgrid.git] / examples / lua / kademlia / tools.lua
1 -- Copyright (c) 2012, 2014. The SimGrid Team.
2 -- All rights reserved.
3
4 -- This program is free software; you can redistribute it and/or modify it
5 -- under the terms of the license (GNU LGPL) which comes with this package.
6
7 function bxor (a,b)
8   local r = 0
9   for i = 0, 31 do
10     local x = a / 2 + b / 2
11     if x ~= math.floor (x) then
12       r = r + 2^i
13     end
14     a = math.floor (a / 2)
15     b = math.floor (b / 2)
16   end
17   return r
18 end
19
20 function index_of(table, o)
21         for i,v in pairs(table) do
22                 if v == o then
23                         return i;
24                 end
25         end
26         return -1
27 end
28 function is_integer(x)
29 return math.floor(x)==x
30 end