Skip to content

Commit

Permalink
Force favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
purplesyringa committed Nov 9, 2024
1 parent 263d4c3 commit 4a6f5a3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion blog/_index_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>purplesyringa's blog</title>
<link rel="icon" href="{{ root }}/favicon.ico" />
<link rel="icon" href="{{ root }}/favicon.ico?v=2" />
<link rel="stylesheet" type="text/css" href="../all.css">
<link rel="stylesheet" type="text/css" href="../blog.css">
<link rel="stylesheet" type="text/css" href="../vendor/Temml-Local.css">
Expand Down
2 changes: 1 addition & 1 deletion blog/_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ title }} | purplesyringa's blog</title>
<link rel="icon" href="{{ root }}/favicon.ico" />
<link rel="icon" href="{{ root }}/favicon.ico?v=2" />
<link rel="stylesheet" type="text/css" href="{{ root }}/all.css">
<link rel="stylesheet" type="text/css" href="{{ root }}/blog.css">
<link rel="stylesheet" type="text/css" href="{{ root }}/vendor/Temml-Local.css">
Expand Down
2 changes: 1 addition & 1 deletion blog/designing-worlds-fastest-perfect-hash/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctypehtml><html prefix="og: http://ogp.me/ns#"lang=en_US><meta charset=utf-8><meta content=width=device-width,initial-scale=1 name=viewport><title>The road to world's fastest perfect hash | purplesyringa's blog</title><link href=../../favicon.ico rel=icon><link href=../../all.css rel=stylesheet><link href=../../blog.css rel=stylesheet><link href=../../vendor/Temml-Local.css rel=stylesheet><link crossorigin href=https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Roboto+Mono:ital,wght@0,100..700;1,100..700&family=Roboto:ital,wght@0,400;0,700;1,400;1,700&family=Slabo+27px&display=swap rel=stylesheet><link href=../../fonts/webfont.css rel=stylesheet><link media="screen and (prefers-color-scheme: dark"href=../../vendor/atom-one-dark.min.css rel=stylesheet><link media="screen and (prefers-color-scheme: light"href=../../vendor/a11y-light.min.css rel=stylesheet><link title="Blog posts"href=../../blog/feed.rss rel=alternate type=application/rss+xml><meta content="The road to world's fastest perfect hash"property=og:title><meta content=article property=og:type><meta content=https://purplesyringa.moe/blog/designing-worlds-fastest-perfect-hash/og.png property=og:image><meta content=https://purplesyringa.moe/blog/designing-worlds-fastest-perfect-hash/ property=og:url><meta content="I need a hash-table with integer keys. HashMap , right? Wrong. For plot reasons, I need it to perform at ridiculous speeds. So that’s how the journey towards the fastest perfect hash function started."property=og:description><meta content=en_US property=og:locale><meta content="purplesyringa's blog"property=og:site_name><meta content=summary_large_image name=twitter:card><meta content=https://purplesyringa.moe/blog/designing-worlds-fastest-perfect-hash/og.png name=twitter:image><script data-website-id=0da1961d-43f2-45cc-a8e2-75679eefbb69 defer src=https://zond.tei.su/script.js></script><body><header><div class=viewport-container><div class=media><a href=https://github.com/purplesyringa><img alt=GitHub src=../../images/github-mark-white.svg></a></div><h1><a href=/>purplesyringa</a></h1><nav><a href=../..>about</a><a class=current href=../../blog/>blog</a><a href=../../sink/>kitchen sink</a></nav></div></header><section><div class=viewport-container><h2>The road to world's fastest perfect hash</h2><time>November 15, 2024</time><p>I need a hash-table with integer keys. <code>HashMap&LTu32, T></code>, right? Wrong. <em>For plot reasons</em>, I need it to perform at ridiculous speeds. So that’s how the journey towards the fastest perfect hash function started.<p class=next-group><span aria-level=3 class=side-header role=heading><span>Setting the stage</span></span>Okay, so a little bit of context is necessary.<p>I’m working with a file containing structured data, and I need to attach metadata to some of the entries. Entries don’t have any natural keys, so I have to use the file offset as the key. I’m allowed to spend a long time preprocessing the file, but after that, mapping the offset to the metadata needs to be near-instantaneous.<p class=next-group><span aria-level=3 class=side-header role=heading><span>PHFs</span></span>Problems like this are typically solved is by using <em>perfect hash functions</em>. These are hash functions trained on a particular key set, with a lucky property that the hashes of these keys don’t collide.<p>For example, for the key set <eq><math><mrow><mo form=prefix stretchy=false>{</mo><mn>12534</mn><mo separator=true>,</mo><mn>12421</mn><mo separator=true>,</mo><mn>123567</mn><mo form=postfix stretchy=false>}</mo></mrow></math></eq>, <eq><math><mrow><mi>H</mi><mo form=prefix stretchy=false>(</mo><mi>x</mi><mo form=postfix stretchy=false>)</mo><mo>=</mo></mrow><mrow><mi>x</mi><mi>&</mi><mn>3</mn></mrow></math></eq> is a valid PHF, because the hashes of the set are <eq><math><mrow><mo form=prefix stretchy=false>{</mo><mn>3</mn><mo separator=true>,</mo><mn>2</mn><mo separator=true>,</mo><mn>1</mn><mo form=postfix stretchy=false>}</mo></mrow></math></eq> with no collisions. Note that collisions may arise if <em>other</em> unlisted keys are hashed: this is not considered a problem.<p>After the PHF is built, we can just put the metadata into an array like this:<pre><code class=language-rust><span class=hljs-keyword>let</span> <span class=hljs-variable>hashtable</span> = [
<!doctypehtml><html prefix="og: http://ogp.me/ns#"lang=en_US><meta charset=utf-8><meta content=width=device-width,initial-scale=1 name=viewport><title>The road to world's fastest perfect hash | purplesyringa's blog</title><link href=../../favicon.ico?v=2 rel=icon><link href=../../all.css rel=stylesheet><link href=../../blog.css rel=stylesheet><link href=../../vendor/Temml-Local.css rel=stylesheet><link crossorigin href=https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Roboto+Mono:ital,wght@0,100..700;1,100..700&family=Roboto:ital,wght@0,400;0,700;1,400;1,700&family=Slabo+27px&display=swap rel=stylesheet><link href=../../fonts/webfont.css rel=stylesheet><link media="screen and (prefers-color-scheme: dark"href=../../vendor/atom-one-dark.min.css rel=stylesheet><link media="screen and (prefers-color-scheme: light"href=../../vendor/a11y-light.min.css rel=stylesheet><link title="Blog posts"href=../../blog/feed.rss rel=alternate type=application/rss+xml><meta content="The road to world's fastest perfect hash"property=og:title><meta content=article property=og:type><meta content=https://purplesyringa.moe/blog/designing-worlds-fastest-perfect-hash/og.png property=og:image><meta content=https://purplesyringa.moe/blog/designing-worlds-fastest-perfect-hash/ property=og:url><meta content="I need a hash-table with integer keys. HashMap , right? Wrong. For plot reasons, I need it to perform at ridiculous speeds. So that’s how the journey towards the fastest perfect hash function started."property=og:description><meta content=en_US property=og:locale><meta content="purplesyringa's blog"property=og:site_name><meta content=summary_large_image name=twitter:card><meta content=https://purplesyringa.moe/blog/designing-worlds-fastest-perfect-hash/og.png name=twitter:image><script data-website-id=0da1961d-43f2-45cc-a8e2-75679eefbb69 defer src=https://zond.tei.su/script.js></script><body><header><div class=viewport-container><div class=media><a href=https://github.com/purplesyringa><img alt=GitHub src=../../images/github-mark-white.svg></a></div><h1><a href=/>purplesyringa</a></h1><nav><a href=../..>about</a><a class=current href=../../blog/>blog</a><a href=../../sink/>kitchen sink</a></nav></div></header><section><div class=viewport-container><h2>The road to world's fastest perfect hash</h2><time>November 15, 2024</time><p>I need a hash-table with integer keys. <code>HashMap&LTu32, T></code>, right? Wrong. <em>For plot reasons</em>, I need it to perform at ridiculous speeds. So that’s how the journey towards the fastest perfect hash function started.<p class=next-group><span aria-level=3 class=side-header role=heading><span>Setting the stage</span></span>Okay, so a little bit of context is necessary.<p>I’m working with a file containing structured data, and I need to attach metadata to some of the entries. Entries don’t have any natural keys, so I have to use the file offset as the key. I’m allowed to spend a long time preprocessing the file, but after that, mapping the offset to the metadata needs to be near-instantaneous.<p class=next-group><span aria-level=3 class=side-header role=heading><span>PHFs</span></span>Problems like this are typically solved is by using <em>perfect hash functions</em>. These are hash functions trained on a particular key set, with a lucky property that the hashes of these keys don’t collide.<p>For example, for the key set <eq><math><mrow><mo form=prefix stretchy=false>{</mo><mn>12534</mn><mo separator=true>,</mo><mn>12421</mn><mo separator=true>,</mo><mn>123567</mn><mo form=postfix stretchy=false>}</mo></mrow></math></eq>, <eq><math><mrow><mi>H</mi><mo form=prefix stretchy=false>(</mo><mi>x</mi><mo form=postfix stretchy=false>)</mo><mo>=</mo></mrow><mrow><mi>x</mi><mi>&</mi><mn>3</mn></mrow></math></eq> is a valid PHF, because the hashes of the set are <eq><math><mrow><mo form=prefix stretchy=false>{</mo><mn>3</mn><mo separator=true>,</mo><mn>2</mn><mo separator=true>,</mo><mn>1</mn><mo form=postfix stretchy=false>}</mo></mrow></math></eq> with no collisions. Note that collisions may arise if <em>other</em> unlisted keys are hashed: this is not considered a problem.<p>After the PHF is built, we can just put the metadata into an array like this:<pre><code class=language-rust><span class=hljs-keyword>let</span> <span class=hljs-variable>hashtable</span> = [
<span class=hljs-literal>None</span>,
<span class="hljs-title function_ invoke__">Some</span>((<span class=hljs-number>123567</span>, value <span class=hljs-keyword>for</span> <span class=hljs-number>123567</span>)),
<span class="hljs-title function_ invoke__">Some</span>((<span class=hljs-number>12421</span>, value <span class=hljs-keyword>for</span> <span class=hljs-number>12421</span>)),
Expand Down

0 comments on commit 4a6f5a3

Please sign in to comment.