This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local type Distance = number | |
| local type VertexId = number | |
| local record Node | |
| preds: {VertexId:Distance} | |
| succs: {VertexId:Distance} | |
| end | |
| local node_mt: metatable<Node> = { | |
| __index = Node, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| box.orm = require 'orm' . configure { | |
| users = { | |
| format = { | |
| { name = 'uid', type = 'unsigned' }, | |
| { name = 'email', type = 'string' }, | |
| }, | |
| indexes = { | |
| { name = 'primary', parts = { 'uid' } }, | |
| { name = 'email', parts = { 'email', 'uid' } }, | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env tarantool | |
| print(_G._TARANTOOL) | |
| -- box.cfg{} | |
| require 'jit.dump'.start("hotloop=1") | |
| local fiber = require 'fiber' | |
| local log = require 'log' | |
| local json = require 'json' | |
| json.cfg{ encode_use_tostring = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| -- TODO: | |
| -- Support all ops for update | |
| -- Create separate module | |
| local ffi = require 'ffi' | |
| local fiber = require 'fiber' | |
| ffi.cdef[[ | |
| struct header_v11 { | |
| uint32_t header_crc32c; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local Coro = {} | |
| Coro.__index = Coro | |
| local S = { | |
| queue = require 'q'(), | |
| } | |
| function S:push(o) | |
| self.queue:push(o) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/tarantool | |
| local fiber = require 'fiber' | |
| local clock = require 'clock' | |
| local log = require 'log' | |
| local bus = setmetatable({ | |
| put = function(self, msg) | |
| while not self.closed and self.msg ~= nil do | |
| self.cond:wait() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env tarantool | |
| local function stack() | |
| local i = 1 | |
| while debug.getinfo(i) do | |
| i = i * 2 | |
| end | |
| local l, r = math.floor(i/2), i | |
| while l < r - 1 do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local clock = require 'clock'.time | |
| function getms1() | |
| local bench = function(f, ...) | |
| local tail = function(s, ...) | |
| return clock()-s, ... | |
| end | |
| local s = clock() | |
| return tail(s, f(...)) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| collectgarbage('stop') | |
| local MAX = 1000000 | |
| print("50: for+..", clock.bench(function() for j = 1, MAX do local s = "" for i = 1, 50 do s = s .. i end end end)[1]) | |
| print("50: for+table.insert", clock.bench(function() for j = 1, MAX do local s = {} for i = 1, 50 do table.insert(s, i) end table.concat(s) end end)[1]) | |
| print("50: for+table", clock.bench(function() for j = 1, MAX do local s = {} for i = 1, 50 do s[i] = i end table.concat(s) end end)[1]) | |
| print("50: for+table+new", clock.bench(function() for j = 1, MAX do local s = table.new(50, 0) for i = 1, 50 do s[i] = i end table.concat(s) end end)[1]) | |
| print("100: for+..", clock.bench(function() for j = 1, MAX do local s = "" for i = 1, 100 do s = s .. i end end end)[1]) | |
| print("100: for+table.insert", clock.bench(function() for j = 1, MAX do local s = {} for i = 1, 100 do table.insert(s, i) end table.concat(s) end end)[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Execute with tarantool or luajit | |
| assert(jit, "jit required") | |
| local table_new = require 'table.new' | |
| local function tablen(t, len) | |
| local j = len | |
| if j > 1 and t[j] == nil then | |
| -- Use i = 0 here because in Lua tables are 1-indexed: | |
| local i = 0 |