Skip to content
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

Switch on String #12

Open
Simn opened this issue Jun 23, 2013 · 3 comments
Open

Switch on String #12

Simn opened this issue Jun 23, 2013 · 3 comments
Assignees

Comments

@Simn
Copy link
Collaborator

Simn commented Jun 23, 2013

While we can use an if-chain for small switches, it might make sense to look into some hash-based solution for larger ones.

@waneck
Copy link
Owner

waneck commented Jun 24, 2013

I've got a filter working on java, which transforms switch on string into switch on the string's hashcode, with support for collisions. It's not the best since the first time it has to calculate the string's hashcode, but if we cache the hashcode (like Java does), subsequent switches will be very fast

@Simn
Copy link
Collaborator Author

Simn commented Sep 16, 2013

I have added a first version which does some horrible String_equals comparison. We can optimize that later.

@ghost ghost assigned Simn Sep 16, 2013
@ousado
Copy link
Collaborator

ousado commented Sep 26, 2013

  1. group strings by length
  2. identify differences, best case is having a distinct char per string in one and the same position
    simple case:
    "ab"
    "bc"
    "aef"
    "xhi"

switch on length of string and then switch on second char in above example, check whether we actually have a match and we have a result.
Edit: Uhm.. in this example we wouldn't need the switch on length, of course, but in the general case that's a good way to partition the strings into subsets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants