Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
local key = {} --unique key | |
local mt = {__index = function (t) return t[key] end} | |
function setDefault( t, d ) | |
t[key] = d | |
setmetatable(t, mt) | |
end | |
tab = {x=10, y=20} |
function setDefault( t, d ) | |
local mt = {__index = function () return d end} | |
setmetatable(t, mt) | |
end | |
tab = {x=10, y=20} | |
print(tab.x, tab.z) | |
setDefault(tab, 0) | |
print(tab.x, tab.z) |
local index = {} | |
-- create private index | |
local mt = { | |
__index = function ( t, k ) | |
print("*access to element " .. tostring(k)) | |
return t[index][k] --access the original table | |
end, | |
__newindex = function ( t, k, v) |
Set = {} | |
-- create a new set with the values of the | |
-- given list | |
local mt = {} | |
function Set.new(l) | |
local set = {} |
'use strict'; | |
// http://www.infoq.com/cn/presentations/node-js-and-real-time-baas-cloud-development-practice?utm_source=infoq&utm_medium=videos_homepage&utm_campaign=videos_row3 | |
// This is a free list to avoid creating so many same object. | |
exports.Freelist = function(name, max, constructor) { | |
this.name = name; | |
this.constructor = constructor; | |
this.max = max; | |
this.list = []; | |
}; |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
http://www.cnblogs.com/simonw/archive/2007/01/17/622032.html | |
http://blog.csdn.net/hong201/article/details/4153182 | |
http://www.cnblogs.com/simonw/archive/2006/12/20/597986.html |
http://spf13.com/post/ultimate-vim-config |
http://www.gammon.com.au/forum/?id=9908 | |
http://blog.fuqcool.com/2011/04/17/algorithm-shuffle.html | |
http://en.wikipedia.org/wiki/Fisher-Yates_shuffle |
sed -i "s/floating-point/fixed-point/g" `find . -name "*.xml"|xargs grep floating-point -rl` | |
http://www.blogjava.net/hispark/archive/2010/08/14/328851.html | |