GithubHelp home page GithubHelp logo

Q: sort keys to string? about twitter-cldr-rb HOT 5 CLOSED

twitter avatar twitter commented on August 14, 2024
Q: sort keys to string?

from twitter-cldr-rb.

Comments (5)

jrochkind avatar jrochkind commented on August 14, 2024

okay, after studying UTS#10 (UCA) for a few hours, I have determined that the sort keys are 16-bit ints, not 8-bit ints.

I'm still confused over endian-ness issues, with regard to how to turn the sort keys into a string having the desired collation properties. Researching/thinking on it.

from twitter-cldr-rb.

camertron avatar camertron commented on August 14, 2024

I believe collation elements can be expressed in hex, so it stands to reason the sort keys can be as well. Remember that sort keys don't have anything to do with character representation, so encoding them as text won't be that useful (and will likely generate some pretty funky characters all over the Unicode spectrum). Have you considered storing the sort key in hex? Two hex strings can be compared easily, and if that doesn't work, you could always consider converting them back into a byte array:

[39, 61, 51, 1].map { |i| i.to_s(16).rjust(2, "0") }.join  # => 273d3301

And back again:

"273d3301".chars.each_slice(2).map { |s| s.join.to_i(16) }  # => [39, 61, 51, 1]

from twitter-cldr-rb.

jrochkind avatar jrochkind commented on August 14, 2024

Thanks! Hmm, if converted to hex like that, are the output strings still byte-order comparable with desired collation? If so, that might make a lot of sense. I just need a single binary value that can be stored in an external system, and compared for proper collation. Thanks for your tips!

from twitter-cldr-rb.

camertron avatar camertron commented on August 14, 2024

Unless I'm missing something, you should be able to compare two hex-encoded sort keys. The hex digits 0-9 and a-z are conveniently in ascending ASCII order. Here's an easier way to convert (with pack this time):

[39, 61, 51, 1].pack("c*").unpack("H*")  # => ["273d3301"]

from twitter-cldr-rb.

jrochkind avatar jrochkind commented on August 14, 2024

thanks you for your advice!

from twitter-cldr-rb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.