diff options
author | svu <svu> | 2007-03-04 11:50:28 +0000 |
---|---|---|
committer | svu <svu> | 2007-03-04 11:50:28 +0000 |
commit | c758dfcaa7ad8a51c7ffbc2ffc9c434ae1173ad9 (patch) | |
tree | b116d0054ae32e5388191285f8f5f1112b04d301 /tests | |
parent | a1eb532100f99c8d8b5be5f5685c25b0484b3ecd (diff) |
more playing with inet processing
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/ruby/find_fragments.rb | 52 | ||||
-rw-r--r-- | tests/ruby/find_match.rb | 8 | ||||
-rw-r--r-- | tests/ruby/utils.rb | 64 | ||||
-rw-r--r-- | tests/ruby/xkbparser.rb | 17 |
4 files changed, 139 insertions, 2 deletions
diff --git a/tests/ruby/find_fragments.rb b/tests/ruby/find_fragments.rb new file mode 100755 index 00000000..118de03b --- /dev/null +++ b/tests/ruby/find_fragments.rb @@ -0,0 +1,52 @@ +#!/usr/bin/ruby +# +# $Id$ +# The script finds the fragments +# + +require "xkbparser.rb" + +baseDir = "../.." + +symbolsDir = "#{baseDir}/symbols" +#symbolsDir = "." + +parser = Parser.new + +allSyms = parser.parse("#{symbolsDir}/inet") + +everything = allSyms.merge + +everything.filter(1) + +#numCombinations = 1 + +#puts "everything:" + +#everything.find_all do | symName, keycodes | +#puts "#{symName}, #{keycodes.length} mappings -> " +# keycodes.find_all do | keycode, counter | +# puts " #{keycode} -> #{counter} occurences" +# end +# numCombinations *= (keycodes.length + 1) +#end + +#puts "Total mappings: #{everything.length}/#{everything.full_length()}, #{numCombinations} combinations" +# + +numCombinations = 0 +allSyms.find_all do | symsName, symbols | + puts "n: #{symsName}" + + # Counting only symbols which used more than once + numDupSymbols = symbols.keys.inject(0) do | rv, keycode | + c = everything.cardinality(keycode, symbols[keycode]) + puts "#{keycode} -> #{symbols[keycode]}, #{c}" + (c > 0) ? rv : rv + 1 + end + + numCombinations += (1 << numDupSymbols) + puts "l: #{symbols.length} d: #{numDupSymbols} c: #{numCombinations}" +end + +puts "numCombinations: #{numCombinations}" diff --git a/tests/ruby/find_match.rb b/tests/ruby/find_match.rb index 5a613dd9..10738faf 100644 --- a/tests/ruby/find_match.rb +++ b/tests/ruby/find_match.rb @@ -1,3 +1,4 @@ +#!/usr/bin/ruby # # $Id$ # The script finds best matching xkb_symbols in symbols/in @@ -8,11 +9,14 @@ require "xkbparser.rb" -basedir = "../.." +baseDir = "../.." + +symbolsDir = "#{baseDir}/symbols" +#symbolsDir = "." parser = Parser.new -allSyms = parser.parse("#{basedir}/symbols/inet") +allSyms = parser.parse("#{symbolsDir}/inet") newSyms = parser.parse(ARGV[0]) limit = ARGV[1].to_i diff --git a/tests/ruby/utils.rb b/tests/ruby/utils.rb new file mode 100644 index 00000000..3c699a7a --- /dev/null +++ b/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 diff --git a/tests/ruby/xkbparser.rb b/tests/ruby/xkbparser.rb index cc67c447..4b15df3d 100644 --- a/tests/ruby/xkbparser.rb +++ b/tests/ruby/xkbparser.rb @@ -6,6 +6,8 @@ # complex XKB format # +require "utils.rb" + class Symbols < Hash # @@ -68,6 +70,11 @@ class Symbols < Hash end end + # Size of all keys + def length() + keys().length() + end + # # Size - takes into account overlapping key definitions # @@ -138,6 +145,16 @@ class SymbolsList < Hash matching end + def merge() + everything = NonuniqueCountingHash.new + find_all do | symsName, syms | + syms.find_all do | symName, keycode | + everything[symName] = keycode + end + end + everything + end + end class Parser |