aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/xkeyboard-config/tests/ruby/find_fragments.rb
blob: 118de03be14567be8f0f0cf23f8fb4175ac894ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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}"