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

Replace endless if (** iswm ..) blocks with hash map #1

Closed
SanderSade opened this issue May 18, 2017 · 12 comments
Closed

Replace endless if (** iswm ..) blocks with hash map #1

SanderSade opened this issue May 18, 2017 · 12 comments

Comments

@SanderSade
Copy link
Collaborator

Might be faster to read filters from file/s into hashmaps and loop over hashmap, then take the appropriate action.

@Sophist-UK
Copy link
Collaborator

Might be.

@Sophist-UK
Copy link
Collaborator

AFAIK, hash tables enable you to look up the value against a key quickly for large numbers of keys. I believe that you can iterate over the hash table too, though that is not their purpose.

I am unsure how we can use a hash table for fast lookup of iswm matching - we can use it as an array and iterate the values in order to get the values to iswm with, but that is unlikely to be any faster then the long list of if iswm.

But if there is a way to use a hash table effectively let me know and I will code it.

@Sophist-UK
Copy link
Collaborator

Sophist-UK commented May 21, 2017

Hmmm - it seems that $hfind(hashtable, message, 1, W) uses the hash table item or data as wildcard text - so perhaps this is possible.

@SanderSade
Copy link
Collaborator Author

Good find, I didn't know about that $hfind() option. My initial idea was just looping over hashmap/items, to make filters more easier to maintain, compared to endless if statements.

The hashmap should also contain the appropriate method to call on match, e.g.:
filter <--> method
*SpR JUKEBOX*filesize* TextSetNickColor
*DCC GET COMPLETE*from*slot*open* DLF_textfilter

@Sophist-UK
Copy link
Collaborator

Yes - we will need different hash tables for each group.

I have this mostly done on my PC (but not yet on GitHub) - when I do the next commit it would be helpful if you could deskcheck old and new code to make sure that I have create a like for like solution.

@Sophist-UK
Copy link
Collaborator

$hfind will be at least one order of magnitude more efficient/faster (and possibly two orders of magnitude) than a loop or list of if statements.

@SanderSade
Copy link
Collaborator Author

It really depends.

Hash map should be O(1), if Khaled has implemented it properly. However, since that $hfind() is a wildcard match on key, it probably loops internally and is O(n).

@Sophist-UK
Copy link
Collaborator

Yes - but it will be machine code (C?) rather than interpreted mIRC script.

@SanderSade
Copy link
Collaborator Author

I presume that mIRC compiles the script internally to bytecode/assembly-like on load and uses that. But you are probably right.

We can always do a performance test if we really care...

@Sophist-UK
Copy link
Collaborator

I don't really care TBH. It was performing OK on my PC as a list of IF statements.

But I think using hashtables is both more elegant and more maintainable.

@SanderSade
Copy link
Collaborator Author

Exactly. The if's just tickle my inner perfectionist in the wrong way.

@Sophist-UK
Copy link
Collaborator

Coded - see #7

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

2 participants