1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2014-05-30 23:58:01 +00:00
parent c39e659263
commit 35348a0806
4 changed files with 1321 additions and 27 deletions

View file

@ -1,4 +1,7 @@
Sat May 31 08:57:42 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
Sat May 31 08:57:58 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* enc/unicode/case-folding.rb (lookup_hash): make perfect hash to
lookup case unfolding table 1.
* enc/unicode/case-folding.rb (lookup_hash): make perfect hash to
lookup case folding table.

View file

@ -240,7 +240,6 @@ static const struct st_hash_type type_code3_hash = {
};
static st_table* Unfold1Table;
static st_table* Unfold2Table;
static st_table* Unfold3Table;
static int CaseFoldInited = 0;
@ -251,14 +250,6 @@ static int init_case_fold_table(void)
THREAD_ATOMIC_START;
Unfold1Table = st_init_numtable_with_size(UNFOLD1_TABLE_SIZE);
if (ONIG_IS_NULL(Unfold1Table)) return ONIGERR_MEMORY;
for (i = 0; i < numberof(CaseUnfold_11_Table); i++) {
const CaseUnfold_11_Type *p1 = &CaseUnfold_11_Table[i];
st_add_direct(Unfold1Table, (st_data_t )p1->from, (st_data_t )&(p1->to));
}
Unfold2Table = st_init_table_with_size(&type_code2_hash, UNFOLD2_TABLE_SIZE);
if (ONIG_IS_NULL(Unfold2Table)) return ONIGERR_MEMORY;
@ -281,16 +272,7 @@ static int init_case_fold_table(void)
}
#define onigenc_unicode_fold_lookup onigenc_unicode_CaseFold_11_lookup
static inline const CodePointList3 *
onigenc_unicode_unfold1_lookup(OnigCodePoint code)
{
st_data_t to;
if (onig_st_lookup(Unfold1Table, (st_data_t )code, &to) != 0) {
return (const CodePointList3 *)to;
}
return 0;
}
#define onigenc_unicode_unfold1_lookup onigenc_unicode_CaseUnfold_11_lookup
static inline const CodePointList2 *
onigenc_unicode_unfold2_lookup(const OnigCodePoint *code)

View file

@ -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

File diff suppressed because it is too large Load diff