[sword-devel] [Fwd: BOUNCE sword-devel@crosswire.org: Non-member submission from ["Jeremy Bettis" <jeremyb@hksys.com>]]

Paul Gear sword-devel@crosswire.org
Wed, 13 Jun 2001 20:37:26 +1000


"Troy A. Griffitts" wrote:

> ...
> If the list is not sparse then the simplest method for conversion would be
> to make an array.
>
> short jis2unicode = { 1,2,3,4,5,6,7,26,6,23,7,2,7, ...etc for all 7000
> mappings...};
> #DEFINE JIS_OFFSET 0 // whatever the first jis character is
> #DEFINE UNICODE_OFFSET 0 // Just to make the numbers in your list smaller,
> you can set this to the smallest value and make all of the rest of them
> relative to it.
>
> short convertJIS2Unicode(short jischar) {
>     return jis2unicode[jischar - JIS_OFFSET] + UNICODE_OFFSET;
> }
>
> This should much smaller than your switch statement.  If the JIS list is
> sparse though, then this will be a much bigger array than 7000 shorts.

That is good advice.  Chris, i think you'll find that such an arrangement would be much more compact and give
better performance than either a hash table or an STL map when the main direction of conversion is from the
shorter, denser encoding to the longer, sparser encoding.  The reverse direction would be slower, but i expect
you'd only need to make such conversions when getting user input for searches and the like, and the number of
lookups would be small.

Paul
http://paulgear.webhop.net