Skip to content

Commit

Permalink
import katex
Browse files Browse the repository at this point in the history
  • Loading branch information
kampersanda committed Dec 5, 2021
1 parent 46fc1bf commit f3b1275
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ bincode = "1.3.3"
default = []
intrinsics = []

[package.metadata.docs.rs]
rustdoc-args = [
"--html-in-header",
"katex.html",
]

[workspace]
members = [
"bench",
Expand Down
33 changes: 33 additions & 0 deletions katex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-RZU/ijkSsFbcmivfdRBQDtwuwVqK7GMOw6IMvKyeWL2K5UAlyp6WonmB8m7Jd0Hn" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-pK1WpvzWVBQiP0/GjnvRxV4mOb0oxFuyRxJlk6vVw146n3egcN5C925NCP7a7BY8" crossorigin="anonymous"></script>
<script>
"use strict";
document.addEventListener("DOMContentLoaded", function () {
var maths = document.getElementsByClassName("language-math");
for (var i=0; i<maths.length; i++) {
var el = maths[i];
katex.render(el.innerText, el, {displayMode: true});
}

var codes = document.getElementsByTagName("code");
for (i=0; i<codes.length; i++) {
el = codes[i];
if (el.classList.contains("language-math")) continue;
if (el.classList.contains("language-inline-math")) {
katex.render(el.innerText, el);
continue;
}

var parent = el.parentNode;
if (parent.nodeName.toLowerCase() === "pre") continue;
// TODO: Can this be done with DOM manipulation rather than string manipulation?
// https://stackoverflow.com/q/48438067/3019990
var inlineMath = "$" + el.outerHTML + "$";
if (parent.innerHTML.indexOf(inlineMath) !== -1) {
el.classList.add("language-inline-math");
parent.innerHTML = parent.innerHTML.replace("$" + el.outerHTML + "$", el.outerHTML);
i--;
}
}
});
</script>
10 changes: 5 additions & 5 deletions src/elias_fano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use serde::{Deserialize, Serialize};
/// Compressed monotone increasing sequence through Elias-Fano encoding.
///
/// [`EliasFano`] implements an Elias-Fano representation for monotone increasing sequences.
/// It can store a very sparse sequence in compressed space.
/// When a sequence stores $`n`$ integers from $`[0, u-1]`$, this representation takes $`n \lceil \log_2 \frac{u}{n} \rceil + 2n`$ bits of space.
/// That is, a sparse sequence can be stored in a very compressed space.
///
/// This is a yet another Rust port of [succinct::elias_fano](https://github.com/ot/succinct/blob/master/elias_fano.hpp).
///
Expand Down Expand Up @@ -280,7 +281,7 @@ impl EliasFano {
self.len() == 0
}

/// Gets the max of stored integers.
/// Gets the (exclusive) upper bound of integers.
#[inline(always)]
pub const fn universe(&self) -> usize {
self.universe
Expand All @@ -303,10 +304,9 @@ impl EliasFanoBuilder {
///
/// # Arguments
///
/// - `universe`: The max of integers to be stored.
/// - `universe`: The (exclusive) upper bound of integers to be stored, i.e., an integer in `[0..universe - 1]`.
/// - `num_ints`: The number of integers to be stored.
pub fn new(universe: usize, num_ints: usize) -> Self {
assert_ne!(universe, 0);
assert_ne!(num_ints, 0);
let low_len = broadword::msb(universe / num_ints).unwrap_or(0);
Self {
Expand All @@ -326,7 +326,7 @@ impl EliasFanoBuilder {
///
/// - `i`: Pushed integer that must be no less than the last one.
pub fn push(&mut self, i: usize) {
assert!(i >= self.last && i <= self.universe);
assert!(i >= self.last && i < self.universe);
assert!(self.pos < self.num_ints);
self.last = i;
let low_mask = (1 << self.low_len) - 1;
Expand Down

0 comments on commit f3b1275

Please sign in to comment.