Skip to content

Instantly share code, notes, and snippets.

@sugarflowers
Created June 27, 2025 07:46
Show Gist options
  • Save sugarflowers/12ef58a9c4efe5a744fae85729ec0530 to your computer and use it in GitHub Desktop.
Save sugarflowers/12ef58a9c4efe5a744fae85729ec0530 to your computer and use it in GitHub Desktop.
include "logic.lua"
include "dprt.lua"
do
	local lk = Links.new()
	
	local links = { 3,0, 3,1, 4,0, 4,3, 
		   5,1, 5,3, 6,4, 6,5,
		   7,2, 7,6, 8,6, 8,7,
		   9,2, 9,7, 10,8, 10,9,
		   11,3, 11,7}
		   
	print(lk:set_links(links))
	--print(lk:set_links(links))
	--print(lk:set_links(links))
	
	dprt(lk.link)
end
--include "dprt.lua"

Links = {}
Links.new = function()
	local buf = {}
	
	buf.offset = 0 -- offset
	buf.phase = 0
	buf.link = {}

	buf.set_links = function(self, links)
		ret_offset = self.offset -- offset
		for i=1, #links, 2 do
			target = links[i]
			sender = links[i+1]
			if self.link[target] == nil then
				self.link[target] = {}
				self.offset += 1 -- offset
			end	
			table.insert(self.link[target], sender)
			local cnt = #self.link[target]
			--print(target .. ", " .. cnt)
		end
		return ret_offset -- offset
	end

	return buf
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment