Last active
October 9, 2015 11:38
-
-
Save Constellation/3498498 to your computer and use it in GitHub Desktop.
Revisions
-
Constellation revised this gist
Jan 17, 2013 . 1 changed file with 0 additions and 15 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,21 +5,6 @@ var module = (function (exports) { NameSequence = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); ZeroSequenceCache = []; function stringRepeat(str, num) { var result = ''; -
Constellation revised this gist
Aug 28, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -50,11 +50,11 @@ var module = (function (exports) { ch = name.charAt(cur); index = NameSequence.indexOf(ch); if (index !== (NameSequence.length - 1)) { return name.substring(0, cur) + NameSequence[index + 1] + zeroSequence(name.length - (cur + 1)); } --cur; } while (cur >= 0); return 'a' + zeroSequence(name.length); } exports.generateNextName = generateNextName; -
Constellation revised this gist
Aug 28, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -47,7 +47,7 @@ var module = (function (exports) { cur = name.length - 1; do { ch = name.charAt(cur); index = NameSequence.indexOf(ch); if (index !== (NameSequence.length - 1)) { return name.substring(0, cur) + NameSequence[index + 1] + stringRepeat('0', name.length - (cur + 1)); -
Constellation created this gist
Aug 28, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ var module = (function (exports) { var NameSequence, ZeroSequenceCache; NameSequence = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); ZeroSequenceCache = []; function deepCopy(obj) { var key, val, result; result = {}; for (key in obj) { if (obj.hasOwnProperty(key)) { val = obj[key]; if (typeof val === 'object' && val !== null) { val = deepCopy(val); } result[key] = val; } } return result; } function stringRepeat(str, num) { var result = ''; for (num |= 0; num > 0; num >>>= 1, str += str) { if (num & 1) { result += str; } } return result; } function zeroSequence(num) { var res = ZeroSequenceCache[num]; if (res !== undefined) { return res; } res = stringRepeat('0', num); ZeroSequenceCache[num] = res; return res; } function generateNextName(name) { var ch, index, cur; cur = name.length - 1; do { ch = name[cur]; index = NameSequence.indexOf(ch); if (index !== (NameSequence.length - 1)) { return name.substring(0, cur) + NameSequence[index + 1] + stringRepeat('0', name.length - (cur + 1)); } --cur; } while (cur >= 0); return 'a' + stringRepeat('0', name.length); } exports.generateNextName = generateNextName; return exports; })({}); var name = 'a'; for (var i = 0; i < 10000000000; ++i) { print(name); name = module.generateNextName(name); }