diff options
author | marha <marha@users.sourceforge.net> | 2010-08-02 08:29:58 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2010-08-02 08:29:58 +0000 |
commit | d2758df0a0091496717fe7a65c3e7563e7c82785 (patch) | |
tree | 5cb4f95ca29e85f6f732ef4a25e417ed5c2b8d54 /xorg-server/xkeyboard-config/tests/ruby/utils.rb | |
parent | 022d9c6cf6a67385d84ff33ce095f5c7f9f6d0cc (diff) | |
download | vcxsrv-d2758df0a0091496717fe7a65c3e7563e7c82785.tar.gz vcxsrv-d2758df0a0091496717fe7a65c3e7563e7c82785.tar.bz2 vcxsrv-d2758df0a0091496717fe7a65c3e7563e7c82785.zip |
xserver libX11 libXdmcp git update 2-8-2010
Diffstat (limited to 'xorg-server/xkeyboard-config/tests/ruby/utils.rb')
-rw-r--r-- | xorg-server/xkeyboard-config/tests/ruby/utils.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/xorg-server/xkeyboard-config/tests/ruby/utils.rb b/xorg-server/xkeyboard-config/tests/ruby/utils.rb new file mode 100644 index 000000000..93ff0ee5e --- /dev/null +++ b/xorg-server/xkeyboard-config/tests/ruby/utils.rb @@ -0,0 +1,64 @@ +#
+# $Id$
+#
+# Commont classes
+#
+
+#
+# The hash containing non-unique mappings
+# It can have a->b and a->c together
+# Also, for every mapping it counts the number of times this mapping was set
+#
+class NonuniqueCountingHash < Hash
+
+ alias get_original []
+ alias put_original []=
+
+ def []=(key, value)
+ own = self.get_original(key)
+ hash = get_original(key)
+ if hash.nil?
+ put_original(key, hash = Hash.new)
+ end
+ if hash.has_key?(value)
+ hash[value] += 1
+ else
+ hash[value] = 1
+ end
+ end
+
+ #
+ # Number of all mappings (a->b and a->c counted as 2 mappings)
+ #
+ def full_length()
+ values.inject(0) do | rv, hash |
+ rv + hash.length
+ end
+ end
+
+ def cardinality(key1, key2)
+ if has_key?(key1)
+ hash = get_original(key1)
+ if hash.has_key?(key2)
+ hash[key2]
+ else
+ 0
+ end
+ else
+ 0
+ end
+ end
+
+ def filter(limit)
+ find_all do | key, hash |
+ hash.find_all do | key1, counter |
+ if (counter <= limit)
+ hash.delete(key1)
+ end
+ end
+ if hash.empty?
+ delete(key)
+ end
+ end
+ end
+end
|