summaryrefslogtreecommitdiff
path: root/enc/unicode/case-folding.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-30 23:58:01 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-30 23:58:01 +0000
commit35348a080631d9cc06e38972e2752ecc64c1eede (patch)
treeffa54ec452a0b6a1f72fde44b7a0e81846fff922 /enc/unicode/case-folding.rb
parentc39e659263b9a988c39ff97aca3ffde9a482e4e4 (diff)
case-folding.rb: perfect hash for case unfolding1
* enc/unicode/case-folding.rb (lookup_hash): make perfect hash to lookup case unfolding table 1. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc/unicode/case-folding.rb')
-rwxr-xr-xenc/unicode/case-folding.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/enc/unicode/case-folding.rb b/enc/unicode/case-folding.rb
index 0ccc822..a877100 100755
--- a/enc/unicode/case-folding.rb
+++ b/enc/unicode/case-folding.rb
@@ -86,12 +86,13 @@ class CaseFolding
argdecl = "const OnigCodePoint #{argname}"
n = 7
m = (1 << n) - 1
- min, max = data.map {|c, *|c}.minmax
+ min, max = data.map {|c, *|c}.flatten.minmax
src = IO.popen(gperf, "r+") {|f|
f << "short\n%%\n"
data.each_with_index {|(k, _), i|
- ks = [(k >> n*2) & m, (k >> n) & m, (k) & m].map {|c| "\\x%.2x" % c}.join("")
- f.printf "\"%s\", ::::/*0x%.4x*/ %d\n", ks, k, i
+ k = Array(k)
+ ks = k.map {|j| [(j >> n*2) & m, (j >> n) & m, (j) & m]}.flatten.map {|c| "\\x%.2x" % c}.join("")
+ f.printf "\"%s\", ::::/*%s*/ %d\n", ks, k.map {|c| "0x%.4x" % c}.join(","), i
}
f << "%%\n"
f.close_write
@@ -143,7 +144,8 @@ class CaseFolding
# CaseUnfold_11 + CaseUnfold_11_Locale
name = "CaseUnfold_11"
- print_table(dest, name, name=>unfold[0], "#{name}_Locale"=>unfold_locale[0])
+ data = print_table(dest, name, name=>unfold[0], "#{name}_Locale"=>unfold_locale[0])
+ dest.print lookup_hash(name, "CodePointList3", data)
# CaseUnfold_12 + CaseUnfold_12_Locale
name = "CaseUnfold_12"
@@ -154,8 +156,6 @@ class CaseFolding
print_table(dest, name, name=>unfold[2])
# table sizes
- unfold1_table_size = unfold[0].size + unfold_locale[0].size
- dest.printf("#define UNFOLD1_TABLE_SIZE\t%d\n", (unfold1_table_size * 1.2))
unfold2_table_size = unfold[1].size + unfold_locale[1].size
dest.printf("#define UNFOLD2_TABLE_SIZE\t%d\n", (unfold2_table_size * 1.5))
unfold3_table_size = unfold[2].size