-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit the growth of string length when calling Mudder repeatedly but one-at-a-time #7
Comments
Per my email describing the fix: function demo(numDivisions) {
var arr = ['yo'];
for (var i = 0; i < 100; i++) {
arr.push(mudder.base62.mudder(arr[arr.length - 1], '', 1, undefined, numDivisions)[0]);
};
return arr.join(' ');
}
console.log(demo(undefined));
with the following: console.log(demo(10));
In the first example, each time you ask In the second example, you still ask In your situation, where you might want to insert a million entries: console.log(demo(1e6));
These are the first hundred strings you'd get while subdividing a million-fold at each string. |
Hi @fasiha. Imagine the opposite situation.
With the demo function like this: function demo(numDivisions) {
var arr = ['yo'];
for (var i = 0; i < 100; i++) {
arr.unshift(mudder.base62.mudder('', arr[0], 1, undefined, numDivisions)[0]);
};
return arr.join(' ');
} Output for demo(undefined):
Output for demo(100):
The problem is, I need to create new items and insert them at the top of the list. What's your suggestion? Thank you |
@joaonice thanks for reaching out with this knotty problem. Consider this: function demo(numDivisions) {
var arr = ['yo'];
for (var i = 0; i < 50; i++) {
arr.unshift(mudder.base62.mudder(arr[0], '0', 1, undefined, numDivisions)[0]);
};
return arr.join(' ');
}
console.log(demo())
// 0000000001 0000000003 0000000007 000000000F 000000000V 000000001 000000003 000000007 00000000F 00000000V 00000001 00000003 00000007 0000000F 0000000V 0000001 0000003 0000007 000000F 000000V 000001 000003 000007 00000F 00000V 00001 00003 00007 0000F 0000V 0001 0003 0007 000F 000V 001 003 007 00F 00V 01 03 07 0F 0V 1 3 7 F U yo
console.log(demo(100))
// B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y yo The difference between this
With this change, you get the expected behavior. This change is important because Mudder treats the So you were asking Mudder: Meanwhile, I'm asking Mudder: Hopefully this solves your problem? I do agree that this is 😑… I will update the documentation to stress this directionality in the behavior of It would be nice if you could ask Mudder for How annoying is it to have to specifically ask to go from |
Is it possible to compute only first element from muddler if I only need first one? For example: const numDivisions = 10000;
mudder.base62.mudder(arr[0], '0', 1, undefined, numDivisions)[0] In above example, I only need 1st element, but muddler will still compute 10000 even tho almost all of them are never used. Use case: I have sorted list, where first possible index would be I now want to put new item on top of the list. So I'd do "take first index we know and 'reduce' it by say 10000 possible slots and use it. |
@pie6k I may be misunderstanding but I don't think the statement above is correct? For What the If I'm understanding the question, Mudder should already be doing what you want. Does that make sense or am I misunderstanding you? |
Thanks for response. I did put huge numDivisions because I want to 'use' my free namespace space below current lowest index slowly. Let's say So I look for string between If I use string in the middle ( I also don't want 'new lowest' index to be directly next to previous one. Say previous lowest was |
@pie6k yeahhhh I think I understand! I think what you're pointing out is the following problem: mudder.base62.mudder('n', 'a', 1, undefined, 100) // [ 'm' ]
mudder.base62.mudder('n', 'a', 1, undefined, 1000) // [ 'm' ]
mudder.base62.mudder('n', 'a', 1, undefined, 10_000) // [ 'm' ] As you increase Am I finally understanding you? If so, I just added a feature that helps with that (I haven't released it yet, it's in PR #21): mudder.base62.mudder('n', 'a', 1, undefined, 10, 4) // [ 'lh' ]
mudder.base62.mudder('n', 'a', 1, undefined, 100, 4) // [ 'mrw' ]
mudder.base62.mudder('n', 'a', 1, undefined, 1000, 4) // [ 'mzC' ]
mudder.base62.mudder('n', 'a', 1, undefined, 10000, 4) // [ 'mzv0' ] Notice that there's another parameter at the end of these calls. In the code that's called Let me know if that helps, or if I'm still misunderstanding you and this won't help you. (I'll probably still release this as v2.1 anyway since it's a nice feature. It only happens when you're going "backwards" like from |
Love the library and this new feature. However it is a little hard to understand from the readme alone how things work exactly. I just decided to blindly use it and hope for the best. However I think the library itself has a lot of thought put to it, it would be great if it was possible to understand the API and implications of all the different parameters easier. Thanks! |
@Inviz I definitely see what you mean, thanks so much for raising this as an issue!! The library started out with a small API and it has steadily grown as our understanding of the various ways it can be used has evolved and so the terse API docs are no longer sufficient to explain all the arguments and when you might use them! I'm planning on adding a big "Examples" section to the README to address this. I'll tag you in the PR when it lands just in case you're available for a review. (I'm not sure when that'll be, I feel so stupid about how busy I am lately.) But I will say that, for the vast majority of use cases, the first two or three arguments are all you need (e.g., |
Yes definitely, the base case seems very easy. Although your lib offers very distinctive good features, and I'd love to understand the correct way to use them. So if I may make a suggestion, what i'd love in readme is typical use cases and options for them. Something like
Would be superhelpful for people to find their use case |
@Inviz sorry it took a while, can you maybe take a look at #22 and tell me what you think? It doesn't explicitly address your bullets (1) and (2) because I'm not sure what to say about the case where you have frequent inserts vs infrequent inserts—the behavior of the growth of strings depends on whether the inserts are always on the same side of an interval (for example, var start = 'n';
var end='l';
for (let i=0; i < 10; i++) {end = mudder.base62.mudder(start, end)[0];}
console.log(end) that is, constantly splitting the space between But I hope #22 is useful by answering some more straightforward questions about how to use the library? Totally open to feedback. |
Via email:
The text was updated successfully, but these errors were encountered: