Skip to content

Commit b3ac9b4

Browse files
committed
Add dev container
1 parent ea23b83 commit b3ac9b4

File tree

4 files changed

+73
-14
lines changed

4 files changed

+73
-14
lines changed

.devcontainer/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/rust/.devcontainer/base.Dockerfile
2+
3+
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
4+
ARG VARIANT="buster"
5+
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT}
6+
7+
# [Optional] Uncomment this section to install additional packages.
8+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9+
# && apt-get -y install --no-install-recommends <your-package-list-here>

.devcontainer/devcontainer.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/rust
3+
{
4+
"name": "Rust",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
"args": {
8+
// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
9+
// Use bullseye when on local on arm64/Apple Silicon.
10+
"VARIANT": "bullseye"
11+
}
12+
},
13+
"runArgs": [
14+
"--cap-add=SYS_PTRACE",
15+
"--security-opt",
16+
"seccomp=unconfined"
17+
],
18+
19+
// Configure tool-specific properties.
20+
"customizations": {
21+
// Configure properties specific to VS Code.
22+
"vscode": {
23+
// Set *default* container specific settings.json values on container create.
24+
"settings": {
25+
"lldb.executable": "/usr/bin/lldb",
26+
// VS Code don't watch files under ./target
27+
"files.watcherExclude": {
28+
"**/target/**": true
29+
},
30+
"rust-analyzer.checkOnSave.command": "clippy"
31+
},
32+
33+
// Add the IDs of extensions you want installed when the container is created.
34+
"extensions": [
35+
"vadimcn.vscode-lldb",
36+
"mutantdino.resourcemonitor",
37+
"rust-lang.rust-analyzer",
38+
"tamasfe.even-better-toml",
39+
"serayuzgur.crates"
40+
]
41+
}
42+
},
43+
44+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
45+
// "forwardPorts": [],
46+
47+
// Use 'postCreateCommand' to run commands after the container is created.
48+
// "postCreateCommand": "rustc --version",
49+
50+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
51+
"remoteUser": "vscode",
52+
"features": {
53+
"git": "os-provided"
54+
}
55+
}

array-rotate/src/lib.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
fn rotate(array: &[i32], factor: i32) -> Vec<i32> {
2-
let append = if factor > 0 { false } else { true };
2+
let append = factor <= 0;
33
let length: usize = array.len();
44
if length < 1 {
55
return Vec::with_capacity(0);
66
}
77
// Remove sign
88
let mut f: usize = if factor < 0 { !factor + 1 } else { factor } as usize;
9-
f = f % length;
9+
f %= length;
1010
let mut response: Vec<i32> = Vec::with_capacity(length);
1111

1212
for i in 0..length {
@@ -16,16 +16,14 @@ fn rotate(array: &[i32], factor: i32) -> Vec<i32> {
1616
} else {
1717
response.push(array[i - f]);
1818
}
19+
} else if i < length - f {
20+
response.push(array[i + f]);
1921
} else {
20-
if i < length - f {
21-
response.push(array[i + f]);
22-
} else {
23-
response.push(array[i + f - length]);
24-
}
22+
response.push(array[i + f - length]);
2523
}
2624
}
2725

28-
return response;
26+
response
2927
}
3028

3129
#[cfg(test)]

sorting/src/merge_sort/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ pub fn top_down_merge_sort_par(input: &mut [i32], work: &mut [i32]) {
3333
let result = rayon::ThreadPoolBuilder::new()
3434
.num_threads(num_cpus::get() - 2)
3535
.build();
36-
match result {
37-
Ok(pool) => {
38-
top_down_split_merge_par(input, work, &pool);
39-
}
40-
Err(_) => {}
36+
if let Ok(pool) = result {
37+
top_down_split_merge_par(input, work, &pool);
4138
}
4239
}
4340

@@ -98,7 +95,7 @@ pub fn bottom_up_merge_sort(input: &mut [i32], work: &mut [i32]) {
9895
);
9996

10097
// Same as i + 2 * width
101-
i = i + width_x2;
98+
i += width_x2;
10299
}
103100

104101
// Now work array is full of runs of length 2*width.

0 commit comments

Comments
 (0)