xjdrew / lua-zset Goto Github PK
View Code? Open in Web Editor NEWlua data structure same as redis sorted set
lua data structure same as redis sorted set
大多数编程语言本身都提供数组类型,并且可以自定义排序。以lua为例
local list = { {name="a", count=1}, {name="b", count=2 }
table.sort(list, function(a, b)
if a.count ~= b.count then
return a.count < b.count
else
return a.name < b.name
end
return false
end)
自定义排序,是为了方便调用端,做复杂的排序比较(复合排序)
redis zset为什么通过score定义排序?按我个人理解,这是为了将多维条件转换成一维条件,去隔离调用端各种乱七八槽的关系,如redis需要支持脚本化编程、两钟语言间据结构转换
谈回贵项目,是想在本地lua环境中提供zsert支持。那么将多维条件转换成一维条件就没必要了,lua业务层不需要老是想着如何转换成一维比较。比较函数可以在zsert.new时定义
local zs = zset.new(function(a, b)
-- todo someting here
end)
我们项目基于zset来做排行榜,我们的排行榜的基础设计是:以一个分数来排序,同分情况下,先上榜的人在前。但是zset只支持一个条件。
我们的现行方案就是直接前面32位放分数,后面32位放一个0xFFFFFFFF-时间戳。结果数值膨胀,分数放不下了。
几个改进方案各有优劣,想问问看作者的想法。
Uncheck mallocs are a bug no matter how good the rest of your code is!
现在我们后端用的是openresty,打算把这个功能加入到openresty中.
尝试编译了下,发现不支持luajit2.1啊.....
一些5.2下的语法jit还是不支持....
这块xjdrew大大能提供支持么....
luaL_checkversion(L);
lua-skiplist.c: In function ‘_delete’:
lua-skiplist.c:40: warning: assignment discards qualifiers from pointer target type
lua-skiplist.c: In function ‘_delete_by_rank’:
lua-skiplist.c:56: warning: implicit declaration of function ‘luaL_checkunsigned’
lua-skiplist.c:65: warning: implicit declaration of function ‘lua_pushunsigned’
lua-skiplist.c: In function ‘_get_rank’:
lua-skiplist.c:82: warning: assignment discards qualifiers from pointer target type
lua-skiplist.c: In function ‘luaopen_skiplist_c’:
lua-skiplist.c:182: warning: implicit declaration of function ‘luaL_checkversion’
lua-skiplist.c:200: warning: implicit declaration of function ‘luaL_newlib’
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.