Merge from rustc
This commit is contained in:
commit
13dbc8443e
119 changed files with 1692 additions and 966 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 2d482e203eb6d6e353814cf1415c5f94e590b9e0
|
||||
Subproject commit 915f9b319c2823f310430ecdecd86264a7870d7e
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 456b904f791751892b01282fd2757904993c4c26
|
||||
Subproject commit eac89a3cbe6c4714e5029ae8b5a1c556fd4e8c42
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit da0f6dad767670da0e8cd5af8a7090db3272f626
|
||||
Subproject commit 41ccb0e6478305401dad92e8fd3d04a4304edb4c
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 6a5accdaf10255882b1e6c59dfe5f1c79ac95484
|
||||
Subproject commit b679e71c2d66c6fe13e06b99ac61773b866213f0
|
||||
|
|
@ -72,6 +72,8 @@
|
|||
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
|
||||
- [riscv64gc-unknown-linux-gnu](platform-support/riscv64gc-unknown-linux-gnu.md)
|
||||
- [riscv64gc-unknown-linux-musl](platform-support/riscv64gc-unknown-linux-musl.md)
|
||||
- [s390x-unknown-linux-gnu](platform-support/s390x-unknown-linux-gnu.md)
|
||||
- [s390x-unknown-linux-musl](platform-support/s390x-unknown-linux-musl.md)
|
||||
- [sparc-unknown-none-elf](./platform-support/sparc-unknown-none-elf.md)
|
||||
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)
|
||||
- [\*-nto-qnx-\*](platform-support/nto-qnx.md)
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ target | notes
|
|||
`powerpc64le-unknown-linux-gnu` | PPC64LE Linux (kernel 3.10, glibc 2.17)
|
||||
[`riscv64gc-unknown-linux-gnu`](platform-support/riscv64gc-unknown-linux-gnu.md) | RISC-V Linux (kernel 4.20, glibc 2.29)
|
||||
[`riscv64gc-unknown-linux-musl`](platform-support/riscv64gc-unknown-linux-musl.md) | RISC-V Linux (kernel 4.20, musl 1.2.3)
|
||||
`s390x-unknown-linux-gnu` | S390x Linux (kernel 3.2, glibc 2.17)
|
||||
[`s390x-unknown-linux-gnu`](platform-support/s390x-unknown-linux-gnu.md) | S390x Linux (kernel 3.2, glibc 2.17)
|
||||
`x86_64-unknown-freebsd` | 64-bit FreeBSD
|
||||
`x86_64-unknown-illumos` | illumos
|
||||
`x86_64-unknown-linux-musl` | 64-bit Linux with musl 1.2.3
|
||||
|
|
@ -367,7 +367,7 @@ target | std | host | notes
|
|||
[`riscv64gc-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/riscv64
|
||||
[`riscv64-linux-android`](platform-support/android.md) | | | RISC-V 64-bit Android
|
||||
[`riscv64-wrs-vxworks`](platform-support/vxworks.md) | ✓ | |
|
||||
`s390x-unknown-linux-musl` | | | S390x Linux (kernel 3.2, musl 1.2.3)
|
||||
[`s390x-unknown-linux-musl`](platform-support/s390x-unknown-linux-musl.md) | | | S390x Linux (kernel 3.2, musl 1.2.3)
|
||||
`sparc-unknown-linux-gnu` | ✓ | | 32-bit SPARC Linux
|
||||
[`sparc-unknown-none-elf`](./platform-support/sparc-unknown-none-elf.md) | * | | Bare 32-bit SPARC V7+
|
||||
[`sparc64-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/sparc64
|
||||
|
|
|
|||
113
src/doc/rustc/src/platform-support/s390x-unknown-linux-gnu.md
Normal file
113
src/doc/rustc/src/platform-support/s390x-unknown-linux-gnu.md
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
# `s390x-unknown-linux-gnu`
|
||||
|
||||
**Tier: 2 (with Host Tools)**
|
||||
|
||||
IBM z/Architecture (s390x) targets (including IBM Z and LinuxONE) running Linux.
|
||||
|
||||
## Target maintainers
|
||||
|
||||
- Ulrich Weigand, <ulrich.weigand@de.ibm.com>, [@uweigand](https://github.com/uweigand)
|
||||
- Josh Stone, <jistone@redhat.com>, [@cuviper](https://github.com/cuviper)
|
||||
|
||||
## Requirements
|
||||
|
||||
This target requires:
|
||||
|
||||
* Linux Kernel version 3.2 or later
|
||||
* glibc 2.17 or later
|
||||
|
||||
Code generated by the target uses the z/Architecture ISA assuming a minimum
|
||||
architecture level of z10 (Eighth Edition of the z/Architecture Principles
|
||||
of Operation), and is compliant with the s390x ELF ABI.
|
||||
|
||||
Reference material:
|
||||
|
||||
* [z/Architecture Principles of Operation][s390x-isa]
|
||||
* [z/Architecture ELF Application Binary Interface][s390x-abi]
|
||||
|
||||
[s390x-isa]: https://publibfp.dhe.ibm.com/epubs/pdf/a227832d.pdf
|
||||
[s390x-abi]: https://github.com/IBM/s390x-abi
|
||||
|
||||
## Building the target
|
||||
|
||||
This target is distributed through `rustup`, and otherwise requires no
|
||||
special configuration.
|
||||
|
||||
If you need to build your own Rust for some reason though, the target can be
|
||||
enabled in `config.toml`. For example:
|
||||
|
||||
```toml
|
||||
[build]
|
||||
target = ["s390x-unknown-linux-gnu"]
|
||||
```
|
||||
|
||||
## Building Rust programs
|
||||
|
||||
On a s390x Linux host, the `s390x-unknown-linux-gnu` target should be
|
||||
automatically installed and used by default.
|
||||
|
||||
On a non-s390x host, add the target:
|
||||
|
||||
```bash
|
||||
rustup target add s390x-unknown-linux-gnu
|
||||
```
|
||||
|
||||
Then cross compile crates with:
|
||||
|
||||
```bash
|
||||
cargo build --target s390x-unknown-linux-gnu
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
There are no special requirements for testing and running the target.
|
||||
For testing cross builds on the host, please refer to the "Cross-compilation
|
||||
toolchains and C code" section below.
|
||||
|
||||
## Cross-compilation toolchains and C code
|
||||
|
||||
Rust code built using the target is compatible with C code compiled with
|
||||
GCC or Clang using the `s390x-unknown-linux-gnu` target triple (via either
|
||||
native or cross-compilation).
|
||||
|
||||
On Ubuntu, a s390x cross-toolchain can be installed with:
|
||||
|
||||
```bash
|
||||
apt install gcc-s390x-linux-gnu g++-s390x-linux-gnu libc6-dev-s390x-cross
|
||||
```
|
||||
|
||||
Depending on your system, you may need to configure the target to use the GNU
|
||||
GCC linker. To use it, add the following to your `.cargo/config.toml`:
|
||||
|
||||
```toml
|
||||
[target.s390x-unknown-linux-gnu]
|
||||
linker = "s390x-linux-gnu-gcc"
|
||||
```
|
||||
|
||||
If your `s390x-linux-gnu-*` toolchain is not in your `PATH` you may need to
|
||||
configure additional settings:
|
||||
|
||||
```toml
|
||||
[target.s390x-unknown-linux-gnu]
|
||||
# Adjust the paths to point at your toolchain
|
||||
cc = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-gcc"
|
||||
cxx = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-g++"
|
||||
ar = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-ar"
|
||||
ranlib = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-ranlib"
|
||||
linker = "/TOOLCHAIN_PATH/bin/s390x-linux-gnu-gcc"
|
||||
```
|
||||
|
||||
To test cross compiled binaries on a non-s390x host, you can use
|
||||
[`qemu`](https://www.qemu.org/docs/master/system/target-s390x.html).
|
||||
On Ubuntu, a s390x emulator can be obtained with:
|
||||
|
||||
```bash
|
||||
apt install qemu-system-s390x
|
||||
```
|
||||
|
||||
Then, in `.cargo/config.toml` set the `runner`:
|
||||
|
||||
```toml
|
||||
[target.s390x-unknown-linux-gnu]
|
||||
runner = "qemu-s390x-static -L /usr/s390x-linux-gnu"
|
||||
```
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
# `s390x-unknown-linux-musl`
|
||||
|
||||
**Tier: 3**
|
||||
|
||||
IBM z/Architecture (s390x) targets (including IBM Z and LinuxONE) running Linux.
|
||||
|
||||
## Target maintainers
|
||||
|
||||
- Ulrich Weigand, <ulrich.weigand@de.ibm.com>, [@uweigand](https://github.com/uweigand)
|
||||
|
||||
## Requirements
|
||||
|
||||
This target requires:
|
||||
|
||||
* Linux Kernel version 3.2 or later
|
||||
* musl 1.2.3 or later
|
||||
|
||||
Code generated by the target uses the z/Architecture ISA assuming a minimum
|
||||
architecture level of z10 (Eighth Edition of the z/Architecture Principles
|
||||
of Operation), and is compliant with the s390x ELF ABI.
|
||||
|
||||
Reference material:
|
||||
|
||||
* [z/Architecture Principles of Operation][s390x-isa]
|
||||
* [z/Architecture ELF Application Binary Interface][s390x-abi]
|
||||
|
||||
[s390x-isa]: https://publibfp.dhe.ibm.com/epubs/pdf/a227832d.pdf
|
||||
[s390x-abi]: https://github.com/IBM/s390x-abi
|
||||
|
||||
## Building the target
|
||||
|
||||
Because it is Tier 3, Rust does not yet ship pre-compiled artifacts for this
|
||||
target.
|
||||
|
||||
Therefore, you can build Rust with support for the target by adding it to the
|
||||
target list in `config.toml`, a sample configuration is shown below.
|
||||
|
||||
```toml
|
||||
[build]
|
||||
target = ["s390x-unknown-linux-musl"]
|
||||
```
|
||||
|
||||
## Building Rust programs
|
||||
|
||||
Rust does not yet ship pre-compiled artifacts for this target. To compile for
|
||||
this target, you will first need to build Rust with the target enabled (see
|
||||
"Building the target" above).
|
||||
|
||||
## Testing
|
||||
|
||||
There are no special requirements for testing and running the target.
|
||||
For testing cross builds on the host, please refer to the "Cross-compilation
|
||||
toolchains and C code" section below.
|
||||
|
||||
## Cross-compilation toolchains and C code
|
||||
|
||||
Rust code built using the target is compatible with C code compiled with
|
||||
GCC or Clang using the `s390x-unknown-linux-musl` target triple (via either
|
||||
native or cross-compilation).
|
||||
|
||||
Depending on your system, you may need to configure the target to use the GNU
|
||||
GCC linker. To use it, add the following to your `.cargo/config.toml`:
|
||||
|
||||
```toml
|
||||
[target.s390x-unknown-linux-musl]
|
||||
linker = "s390x-linux-musl-gcc"
|
||||
```
|
||||
|
||||
If your `s390x-linux-musl-*` toolchain is not in your `PATH` you may need to
|
||||
configure additional settings:
|
||||
|
||||
```toml
|
||||
[target.s390x-unknown-linux-musl]
|
||||
# Adjust the paths to point at your toolchain
|
||||
cc = "/TOOLCHAIN_PATH/bin/s390x-linux-musl-gcc"
|
||||
cxx = "/TOOLCHAIN_PATH/bin/s390x-linux-musl-g++"
|
||||
ar = "/TOOLCHAIN_PATH/bin/s390x-linux-musl-ar"
|
||||
ranlib = "/TOOLCHAIN_PATH/bin/s390x-linux-musl-ranlib"
|
||||
linker = "/TOOLCHAIN_PATH/bin/s390x-linux-musl-gcc"
|
||||
```
|
||||
|
||||
To test cross compiled binaries on a non-s390x host, you can use
|
||||
[`qemu`](https://www.qemu.org/docs/master/system/target-s390x.html).
|
||||
|
|
@ -447,32 +447,3 @@ This flag is **deprecated** and **has no effect**.
|
|||
Rustdoc only supports Rust source code and Markdown input formats. If the
|
||||
file ends in `.md` or `.markdown`, `rustdoc` treats it as a Markdown file.
|
||||
Otherwise, it assumes that the input file is Rust.
|
||||
|
||||
## `--test-builder`: `rustc`-like program to build tests
|
||||
|
||||
Using this flag looks like this:
|
||||
|
||||
```bash
|
||||
$ rustdoc --test-builder /path/to/rustc src/lib.rs
|
||||
```
|
||||
|
||||
Rustdoc will use the provided program to compile tests instead of the default `rustc` program from
|
||||
the sysroot.
|
||||
|
||||
## `--test-builder-wrapper`: wrap calls to the test builder
|
||||
|
||||
Using this flag looks like this:
|
||||
|
||||
```bash
|
||||
$ rustdoc --test-builder-wrapper /path/to/rustc-wrapper src/lib.rs
|
||||
$ rustdoc \
|
||||
--test-builder-wrapper rustc-wrapper1 \
|
||||
--test-builder-wrapper rustc-wrapper2 \
|
||||
--test-builder rustc \
|
||||
src/lib.rs
|
||||
```
|
||||
|
||||
Similar to cargo `build.rustc-wrapper` option, this flag takes a `rustc` wrapper program.
|
||||
The first argument to the program will be the test builder program.
|
||||
|
||||
This flag can be passed multiple times to nest wrappers.
|
||||
|
|
|
|||
|
|
@ -627,3 +627,36 @@ add the `--scrape-tests` flag.
|
|||
|
||||
This flag enables the generation of links in the source code pages which allow the reader
|
||||
to jump to a type definition.
|
||||
|
||||
### `--test-builder`: `rustc`-like program to build tests
|
||||
|
||||
* Tracking issue: [#102981](https://github.com/rust-lang/rust/issues/102981)
|
||||
|
||||
Using this flag looks like this:
|
||||
|
||||
```bash
|
||||
$ rustdoc --test-builder /path/to/rustc src/lib.rs
|
||||
```
|
||||
|
||||
Rustdoc will use the provided program to compile tests instead of the default `rustc` program from
|
||||
the sysroot.
|
||||
|
||||
### `--test-builder-wrapper`: wrap calls to the test builder
|
||||
|
||||
* Tracking issue: [#102981](https://github.com/rust-lang/rust/issues/102981)
|
||||
|
||||
Using this flag looks like this:
|
||||
|
||||
```bash
|
||||
$ rustdoc -Zunstable-options --test-builder-wrapper /path/to/rustc-wrapper src/lib.rs
|
||||
$ rustdoc -Zunstable-options \
|
||||
--test-builder-wrapper rustc-wrapper1 \
|
||||
--test-builder-wrapper rustc-wrapper2 \
|
||||
--test-builder rustc \
|
||||
src/lib.rs
|
||||
```
|
||||
|
||||
Similar to cargo `build.rustc-wrapper` option, this flag takes a `rustc` wrapper program.
|
||||
The first argument to the program will be the test builder program.
|
||||
|
||||
This flag can be passed multiple times to nest wrappers.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ use rustc_errors::{FatalError, struct_span_code_err};
|
|||
use rustc_hir::PredicateOrigin;
|
||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LOCAL_CRATE, LocalDefId};
|
||||
use rustc_hir_analysis::lower_ty;
|
||||
use rustc_hir_analysis::hir_ty_lowering::FeedConstTy;
|
||||
use rustc_hir_analysis::{lower_const_arg_for_rustdoc, lower_ty};
|
||||
use rustc_middle::metadata::Reexport;
|
||||
use rustc_middle::middle::resolve_bound_vars as rbv;
|
||||
use rustc_middle::ty::{self, AdtKind, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, TypingMode};
|
||||
|
|
@ -435,10 +436,10 @@ fn clean_middle_term<'tcx>(
|
|||
fn clean_hir_term<'tcx>(term: &hir::Term<'tcx>, cx: &mut DocContext<'tcx>) -> Term {
|
||||
match term {
|
||||
hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
|
||||
hir::Term::Const(c) => Term::Constant(clean_middle_const(
|
||||
ty::Binder::dummy(ty::Const::from_const_arg(cx.tcx, c, ty::FeedConstTy::No)),
|
||||
cx,
|
||||
)),
|
||||
hir::Term::Const(c) => {
|
||||
let ct = lower_const_arg_for_rustdoc(cx.tcx, c, FeedConstTy::No);
|
||||
Term::Constant(clean_middle_const(ty::Binder::dummy(ct), cx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -625,7 +626,7 @@ fn clean_generic_param<'tcx>(
|
|||
(param.name.ident().name, GenericParamDefKind::Const {
|
||||
ty: Box::new(clean_ty(ty, cx)),
|
||||
default: default.map(|ct| {
|
||||
Box::new(ty::Const::from_const_arg(cx.tcx, ct, ty::FeedConstTy::No).to_string())
|
||||
Box::new(lower_const_arg_for_rustdoc(cx.tcx, ct, FeedConstTy::No).to_string())
|
||||
}),
|
||||
synthetic,
|
||||
})
|
||||
|
|
@ -1813,7 +1814,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
|||
// `const_eval_poly` tries to first substitute generic parameters which
|
||||
// results in an ICE while manually constructing the constant and using `eval`
|
||||
// does nothing for `ConstKind::Param`.
|
||||
let ct = ty::Const::from_const_arg(cx.tcx, const_arg, ty::FeedConstTy::No);
|
||||
let ct = lower_const_arg_for_rustdoc(cx.tcx, const_arg, FeedConstTy::No);
|
||||
let ct = if let hir::ConstArgKind::Anon(hir::AnonConst { def_id, .. }) =
|
||||
const_arg.kind
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ pub(crate) enum LinkFromSrc {
|
|||
/// It returns the `krate`, the source code files and the `span` correspondence map.
|
||||
///
|
||||
/// Note about the `span` correspondence map: the keys are actually `(lo, hi)` of `span`s. We don't
|
||||
/// need the `span` context later on, only their position, so instead of keep a whole `Span`, we
|
||||
/// need the `span` context later on, only their position, so instead of keeping a whole `Span`, we
|
||||
/// only keep the `lo` and `hi`.
|
||||
pub(crate) fn collect_spans_and_sources(
|
||||
tcx: TyCtxt<'_>,
|
||||
|
|
@ -45,9 +45,9 @@ pub(crate) fn collect_spans_and_sources(
|
|||
include_sources: bool,
|
||||
generate_link_to_definition: bool,
|
||||
) -> (FxIndexMap<PathBuf, String>, FxHashMap<Span, LinkFromSrc>) {
|
||||
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
|
||||
|
||||
if include_sources {
|
||||
let mut visitor = SpanMapVisitor { tcx, matches: FxHashMap::default() };
|
||||
|
||||
if generate_link_to_definition {
|
||||
tcx.hir().walk_toplevel_module(&mut visitor);
|
||||
}
|
||||
|
|
@ -76,7 +76,22 @@ impl<'tcx> SpanMapVisitor<'tcx> {
|
|||
} else {
|
||||
LinkFromSrc::External(def_id)
|
||||
};
|
||||
self.matches.insert(path.span, link);
|
||||
// In case the path ends with generics, we remove them from the span.
|
||||
let span = path
|
||||
.segments
|
||||
.last()
|
||||
.map(|last| {
|
||||
// In `use` statements, the included item is not in the path segments.
|
||||
// However, it doesn't matter because you can't have generics on `use`
|
||||
// statements.
|
||||
if path.span.contains(last.ident.span) {
|
||||
path.span.with_hi(last.ident.span.hi())
|
||||
} else {
|
||||
path.span
|
||||
}
|
||||
})
|
||||
.unwrap_or(path.span);
|
||||
self.matches.insert(span, link);
|
||||
}
|
||||
Res::Local(_) => {
|
||||
if let Some(span) = self.tcx.hir().res_span(path.res) {
|
||||
|
|
|
|||
|
|
@ -988,6 +988,12 @@ class VlqHexDecoder {
|
|||
}
|
||||
class RoaringBitmap {
|
||||
constructor(str) {
|
||||
// https://github.com/RoaringBitmap/RoaringFormatSpec
|
||||
//
|
||||
// Roaring bitmaps are used for flags that can be kept in their
|
||||
// compressed form, even when loaded into memory. This decoder
|
||||
// turns the containers into objects, but uses byte array
|
||||
// slices of the original format for the data payload.
|
||||
const strdecoded = atob(str);
|
||||
const u8array = new Uint8Array(strdecoded.length);
|
||||
for (let j = 0; j < strdecoded.length; ++j) {
|
||||
|
|
@ -1053,9 +1059,24 @@ class RoaringBitmap {
|
|||
contains(keyvalue) {
|
||||
const key = keyvalue >> 16;
|
||||
const value = keyvalue & 0xFFFF;
|
||||
for (let i = 0; i < this.keys.length; ++i) {
|
||||
if (this.keys[i] === key) {
|
||||
return this.containers[i].contains(value);
|
||||
// Binary search algorithm copied from
|
||||
// https://en.wikipedia.org/wiki/Binary_search#Procedure
|
||||
//
|
||||
// Format is required by specification to be sorted.
|
||||
// Because keys are 16 bits and unique, length can't be
|
||||
// bigger than 2**16, and because we have 32 bits of safe int,
|
||||
// left + right can't overflow.
|
||||
let left = 0;
|
||||
let right = this.keys.length - 1;
|
||||
while (left <= right) {
|
||||
const mid = Math.floor((left + right) / 2);
|
||||
const x = this.keys[mid];
|
||||
if (x < key) {
|
||||
left = mid + 1;
|
||||
} else if (x > key) {
|
||||
right = mid - 1;
|
||||
} else {
|
||||
return this.containers[mid].contains(value);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -1068,11 +1089,23 @@ class RoaringBitmapRun {
|
|||
this.array = array;
|
||||
}
|
||||
contains(value) {
|
||||
const l = this.runcount * 4;
|
||||
for (let i = 0; i < l; i += 4) {
|
||||
// Binary search algorithm copied from
|
||||
// https://en.wikipedia.org/wiki/Binary_search#Procedure
|
||||
//
|
||||
// Since runcount is stored as 16 bits, left + right
|
||||
// can't overflow.
|
||||
let left = 0;
|
||||
let right = this.runcount - 1;
|
||||
while (left <= right) {
|
||||
const mid = Math.floor((left + right) / 2);
|
||||
const i = mid * 4;
|
||||
const start = this.array[i] | (this.array[i + 1] << 8);
|
||||
const lenm1 = this.array[i + 2] | (this.array[i + 3] << 8);
|
||||
if (value >= start && value <= (start + lenm1)) {
|
||||
if ((start + lenm1) < value) {
|
||||
left = mid + 1;
|
||||
} else if (start > value) {
|
||||
right = mid - 1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1085,10 +1118,22 @@ class RoaringBitmapArray {
|
|||
this.array = array;
|
||||
}
|
||||
contains(value) {
|
||||
const l = this.cardinality * 2;
|
||||
for (let i = 0; i < l; i += 2) {
|
||||
const start = this.array[i] | (this.array[i + 1] << 8);
|
||||
if (value === start) {
|
||||
// Binary search algorithm copied from
|
||||
// https://en.wikipedia.org/wiki/Binary_search#Procedure
|
||||
//
|
||||
// Since cardinality can't be higher than 4096, left + right
|
||||
// cannot overflow.
|
||||
let left = 0;
|
||||
let right = this.cardinality - 1;
|
||||
while (left <= right) {
|
||||
const mid = Math.floor((left + right) / 2);
|
||||
const i = mid * 2;
|
||||
const x = this.array[i] | (this.array[i + 1] << 8);
|
||||
if (x < value) {
|
||||
left = mid + 1;
|
||||
} else if (x > value) {
|
||||
right = mid - 1;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 69e595908e2c420e7f0d1be34e6c5b984c8cfb84
|
||||
Subproject commit 66221abdeca2002d318fde6efff516aab091df0e
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
|
|
@ -521,15 +521,15 @@ checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904"
|
|||
|
||||
[[package]]
|
||||
name = "xshell"
|
||||
version = "0.2.6"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db0ab86eae739efd1b054a8d3d16041914030ac4e01cd1dca0cf252fd8b6437"
|
||||
checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d"
|
||||
dependencies = [
|
||||
"xshell-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xshell-macros"
|
||||
version = "0.2.6"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d422e8e38ec76e2f06ee439ccc765e9c6a9638b9e7c9f2e8255e4d41e8bd852"
|
||||
checksum = "32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue