diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-12-31 11:12:31 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-31 11:35:58 -0500 |
commit | 12d78ef3bbb5cce5085ade12b197c211d26531eb (patch) | |
tree | cdf03b182d63d7dab106d422d4eeeed454e8aa54 | |
parent | 2224bbf5ad3178e9555a2d79805e73a4193ec61f (diff) |
trace-graph: Replace hash looping with a faster hash
Did a little more research and found a nice hash that is quick
and pretty powerful. Based off of Paul Hsieh's super fast hash:
http://www.azillionmonkeys.com/qed/hash.html
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-graph.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/trace-graph.c b/trace-graph.c index 8692fe7..b70e27d 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -735,27 +735,32 @@ button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) | |||
735 | 735 | ||
736 | static gint do_hash(gint val) | 736 | static gint do_hash(gint val) |
737 | { | 737 | { |
738 | int i, x, y; | 738 | int hash, tmp; |
739 | int total = 0; | ||
740 | 739 | ||
740 | /* idle always gets black */ | ||
741 | if (!val) | 741 | if (!val) |
742 | return 0; | 742 | return 0; |
743 | 743 | ||
744 | for (i = 0; i < 32; i++) { | 744 | hash = 12546869; /* random prime */ |
745 | y = 0; | 745 | |
746 | if (val & (1 << i)) { | 746 | /* |
747 | for (x = 0; x < ((i+1) * 13); x++) { | 747 | * The following hash is based off of Paul Hsieh's super fast hash: |
748 | y |= 1 << ((x * 23) & 31); | 748 | * http://www.azillionmonkeys.com/qed/hash.html |
749 | } | 749 | */ |
750 | } else { | 750 | |
751 | for (x = 0; x < ((i+1) * 7); x++) { | 751 | hash += (val & 0xffff); |
752 | y |= 1 << ((x * 17) & 31); | 752 | tmp = (val >> 16) ^ hash; |
753 | } | 753 | hash = (hash << 16) ^ tmp; |
754 | } | 754 | hash += hash >> 11; |
755 | total += y; | 755 | |
756 | } | 756 | hash ^= hash << 3; |
757 | hash += hash >> 5; | ||
758 | hash ^= hash << 4; | ||
759 | hash += hash >> 17; | ||
760 | hash ^= hash << 25; | ||
761 | hash += hash >> 6; | ||
757 | 762 | ||
758 | return total; | 763 | return hash; |
759 | } | 764 | } |
760 | 765 | ||
761 | static void set_color_by_pid(GtkWidget *widget, GdkGC *gc, gint pid) | 766 | static void set_color_by_pid(GtkWidget *widget, GdkGC *gc, gint pid) |