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.
VOSTX4QHUMVJNSCP34WPRESQRN4OBXK7PILA2RMODRFEAU5LJV2QC HIJWP6Q3CXDRIH7PJXN24JVQJF5Y53JKU7NKFPKCATQWI5DHQA3AC R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC SMZJGK56DYOP2CYIYDV3QXVHL5P52IEF34GFBESNMULJDMDLJR2AC JNS2ATVJRXCIBGRFRPPN63OAOQRVV7GE2VRAL3T6YNRXFX6YYMQAC ZUXG2RU4WF5WF7EYU2XQJ6AERLJLOMGDEXWRMGWHT5DR3B7X7MWQC J62CVGNGJZSN7TMTE2SG53O47YG4SJGJFTUFKVOZY4TM4KAC566QC 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