Skip to content

Add short digest implementation - #260

Merged
stevvooe merged 1 commit into
distribution:masterfrom
dmcgowan:short-digests
Apr 29, 2015
Merged

stevvooe merged 1 commit into
distribution:masterfrom
dmcgowan:short-digests

Conversation

@dmcgowan

Copy link
Copy Markdown
Collaborator

Create table for generating and looking up short digests. Any operation involving short codes may be considered secure if the list of digests added to the table is secure.

closes #194

Comment thread digest/short.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What is the use case of this function? Most the time, short codes are just truncated to a certain length (git uses 7). Shouldn't we just pick a prefix length that is reasonably unlikely to collide?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A reasonable length is contextual, this function only provides options. Could add a strict length mode which returns an error if an ambiguity is detected. This implementation is smart enough to always return unique values no matter the length given.

@dmcgowan

Copy link
Copy Markdown
Collaborator Author

Added benchmark, matches expectations of time complexity...
Add and Dump are linear...Lookup is logarithmic

BenchmarkAdd10      30000       40637 ns/op
BenchmarkAdd100     3000        458341 ns/op
BenchmarkAdd1000    100         10566980 ns/op
BenchmarkLookup10   1000000     1369 ns/op
BenchmarkLookup100  1000000     1409 ns/op
BenchmarkLookup1000 1000000     1498 ns/op
BenchmarkDump10     500000      3122 ns/op
BenchmarkDump100    50000       27859 ns/op
BenchmarkDump1000   5000        265343 ns/op

@stevvooe

Copy link
Copy Markdown
Collaborator

@dmcgowan That Add is nasty. Try out a sort.Search plus copy-insertion.

@dmcgowan

Copy link
Copy Markdown
Collaborator Author

Added commit which uses search + slice copy, as expected it is faster for larger arrays

benchmark               old ns/op     new ns/op     delta
BenchmarkAdd10          40884         43642         +6.75%
BenchmarkAdd100         472603        430000        -9.01%
BenchmarkAdd1000        10493745      4576972       -56.38%

@stevvooe

Copy link
Copy Markdown
Collaborator

Let's call the main object ShortTable a DigestSet or something like that. Let's remove the DumpTable for now, since I'm a little shaky on the use case.

Do we also want to be able to iterate over a DigestSet?

@dmcgowan

Copy link
Copy Markdown
Collaborator Author

Renamed to DigestSet and cleaned up some of the comments to explain its general use and relevance to short string lookups. Also moved the dump table function to a non-member function which takes in a digest.

The name DigestSet does stutter and I would prefer to pick a name which is more lint friendly. The name Set may be more appropriate given its generalized use case. WDYT?

@stevvooe

Copy link
Copy Markdown
Collaborator

@dmcgowan I am fine going with Set, since, as we discussed, this very accurate.

Set represents a unique set of digests which allow for efficient lookup.
Dumping short codes is a function which takes in a digest set.
Any operation involving short codes may be considered secure if the list of digests added to the set is the complete list of referenceable digests.
Contains benchmarks for Add, Lookup, and Dump.

Signed-off-by: Derek McGowan <[email protected]> (github: dmcgowan)
@dmcgowan

Copy link
Copy Markdown
Collaborator Author

Updated to Set and went ahead and squashed to one clean commit

@amylindburg amylindburg mentioned this pull request Mar 24, 2015
4 tasks done
@stevvooe stevvooe added this to the Registry/2.1 milestone Apr 29, 2015
@stevvooe

Copy link
Copy Markdown
Collaborator

LGTM!

stevvooe added a commit that referenced this pull request Apr 29, 2015
Add short digest implementation
@stevvooe
stevvooe merged commit 5556cd1 into distribution:master Apr 29, 2015
@dmcgowan
dmcgowan deleted the short-digests branch October 3, 2016 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

propose approach and syntax for "sugary" content digests

2 participants