We need keys to be fixed as we add/delete nodes because we're going to start recording them next inside Nodes to encode edges.
Since there isn't a clear name for nodes in this app, I came up with a way to autogenerate keys.
H3HB2MENN6YV4Y7MGS4FMHKUS4AOV2JHRJRSG27PDTMYHSD2GEAAC 3L7AIL636NDE5BOTG3LXW44CFW7H2QFBH3LGMSF6NYHE7GVXV3UAC R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC 7UWLGLA6FAO42YN6IBEFAKMTDUY26IJAQDBHGHHH55OK2SHUIZHAC KI6LF2LF2LK6Q7SRWN3U4TJ25Y6BGJ2M3AU5FUTN6JIVA2MUBEXAC M2JTUQQL2JBWHMN3JG6KO6NDHZ5X7ZW2RF7HVG4WVMS5TE6DYUPQC NTYP3TWGASXUIEJOGZL5XL5CGZVJ6RCAVO3ZFGCCDIAHQ6FE6TKAC TBPJ5WSRM5IKQH7FTAVYTWWUBWW7G2CLT5M6FN7CMPLD6Y77YIWQC test_to_key = function()check_eq(to_key(0), 'a', 0)check_eq(to_key(1), 'b', 1)-- ...check_eq(to_key(24), 'y', 24)check_eq(to_key(25), 'z', 25)check_eq(to_key(26), 'ba', 26)check_eq(to_key(26*26), 'baa', '3 digit')check_eq(to_key(26*26+1), 'bab', '3 digit/2')check_eq(to_key(26*26*26), 'baaa', '4 digit')end
to_key = function(n)-- represent an integer n in base-26 using a-zlocal result = {}n = math.floor(n)local a = string.byte('a')while n > 0 dolocal digit = n % 26table.insert(result, 1, string.char(digit+a))n = math.floor(n/26)endif #result == 0 thenreturn 'a'endreturn table.concat(result)end
next_key = function()local result = to_key(First_available_id)First_available_id = First_available_id+1return resultend
First_available_id = 1