Skip to content

Add get level from hexagon#15

Open
melrief wants to merge 2 commits into
masterfrom
add_get_level_from_hexagon
Open

Add get level from hexagon#15
melrief wants to merge 2 commits into
masterfrom
add_get_level_from_hexagon

Conversation

@melrief
Copy link
Copy Markdown

@melrief melrief commented Mar 4, 2016

No description provided.

for {
digit <- choose(0, 9)
curr <- gen
} yield curr + digit * (Math.pow(10, pos).toLong)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this you could generate random characters from '0' to '9' and then use the String-argument BigInt constructor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but probably summing BigInts is faster than parsing String

@melrief melrief assigned melrief and shishkin and unassigned melrief Mar 10, 2016
@melrief
Copy link
Copy Markdown
Author

melrief commented Mar 10, 2016

@shishkin can you have a look at this? I would like to use this code.

@shishkin
Copy link
Copy Markdown

Thanks for your effort here. I'm not sure exposing level on the Encoding is a good idea. I tried to make Encoding as dumb and single-purpose as possible - it just encodes/decodes Zone objects to/from an arbitrary representation. Zone already knows about its level: TeraHex.decode(code).level should already do that. Isn't this enough or usable in your case?

Comment thread build.sbt
organization := "net.teralytics",
name := "geohex",
version := "0.1." + sys.env.getOrElse("TRAVIS_BUILD_NUMBER", "0-SNAPSHOT"),
version := "0.2." + sys.env.getOrElse("TRAVIS_BUILD_NUMBER", "0-SNAPSHOT"),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, API of the library is in complete flux and every change is potentially breaking. Especially around JS/JVM interop. I'd refrain from giving a false sense of compatibility and stick to 0.1.x for now.

@melrief
Copy link
Copy Markdown
Author

melrief commented Mar 12, 2016

The reason why I and @ilyabo in particular are not using TeraHex.decode is because it's slow. For interactive applications it's not fine. Having a faster way to get the level of an hexagon can improve the performance of most of the applications. The dashboard, for instance, uses the length of the hexcode minus four. This PR is just moving this functionality from Ilya's code to the library so that also the backend can use it.

@shishkin
Copy link
Copy Markdown

Then I'd rather make Zone decoding faster. Is it slow on JVM too? Can you elaborate on your scenario a bit? Are you getting levels of multiple hexagons in a tight loop? Are they expected to have different levels? Then I can try to micro-benchmark that scenario and see what is the bottleneck. Also, what would acceptable performance be?

@ilyabo
Copy link
Copy Markdown

ilyabo commented Mar 14, 2016

Honestly, I don't think this tiny improvement is worth spending much time in discussions :) Anyways, here's a quick benchmark:

> var t=require('terahex'); console.time('decode');  for (var i=0; i< 1000000; i++) t.decode('1300123123123'+(i%9)).level; console.timeEnd('decode')
decode: 8762ms

> var t=require('terahex'); function level(code) {return code.length - 4}; console.time('strlen');  for (var i=0; i< 1000000; i++) level('130012312312'+(i%9)); console.timeEnd('strlen')
strlen: 13ms

I also think Encoding is the right place for it, because this knowledge is part of the encoding scheme.

If we don't have this function in terahex, we'll end up using the helper functions on both Scala and JS sides for that, as now, which is a bad thing, because it's part of the implementation detail which we shouldn't rely upon and even worse have it reimplemented in multiple places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants