Skip to content

Commit ed7b9a2

Browse files
committed
??: add a lot of more stuff
Signed-off-by: Vitor Savian <[email protected]>
1 parent 9b8d19d commit ed7b9a2

22 files changed

+226
-34
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,4 @@ zig-out/
419419

420420
# Although this was renamed to .zig-cache, let's leave it here for a few
421421
# releases to make it less annoying to work with multiple branches.
422-
zig-cache/
422+
zig-cache/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## This project is to focus on algorithms

cpp/CMakeLists.txt

-23
This file was deleted.

cpp/main.cpp

-9
This file was deleted.
File renamed without changes.

cpp/src/binary-tree/binary-tree.cpp

Whitespace-only changes.

cpp/src/binary-tree/binary-tree.hpp

Whitespace-only changes.

cpp/src/binarysearch/CMakeLists.txt

Whitespace-only changes.

cpp/src/linked_list/CMakeLists.txt

Whitespace-only changes.

cpp/src/main.cpp

Whitespace-only changes.

go/pkg/array/search.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package array
2+
3+
func binarySearch(arr []int) {
4+
5+
}

go/pkg/array/sort.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package array

go/pkg/binary_tree/binary_tree.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package binarytree

go/pkg/binarysearch/search.go

-1
This file was deleted.

rust/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "rust"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

rust/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: u64, right: u64) -> u64 {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

zig/build.zig

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
const std = @import("std");
2+
3+
// Although this function looks imperative, note that its job is to
4+
// declaratively construct a build graph that will be executed by an external
5+
// runner.
6+
pub fn build(b: *std.Build) void {
7+
// Standard target options allows the person running `zig build` to choose
8+
// what target to build for. Here we do not override the defaults, which
9+
// means any target is allowed, and the default is native. Other options
10+
// for restricting supported target set are available.
11+
const target = b.standardTargetOptions(.{});
12+
13+
// Standard optimization options allow the person running `zig build` to select
14+
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
15+
// set a preferred release mode, allowing the user to decide how to optimize.
16+
const optimize = b.standardOptimizeOption(.{});
17+
18+
const lib = b.addStaticLibrary(.{
19+
.name = "zig",
20+
// In this case the main source file is merely a path, however, in more
21+
// complicated build scripts, this could be a generated file.
22+
.root_source_file = b.path("src/root.zig"),
23+
.target = target,
24+
.optimize = optimize,
25+
});
26+
27+
// This declares intent for the library to be installed into the standard
28+
// location when the user invokes the "install" step (the default step when
29+
// running `zig build`).
30+
b.installArtifact(lib);
31+
32+
const exe = b.addExecutable(.{
33+
.name = "zig",
34+
.root_source_file = b.path("src/main.zig"),
35+
.target = target,
36+
.optimize = optimize,
37+
});
38+
39+
// This declares intent for the executable to be installed into the
40+
// standard location when the user invokes the "install" step (the default
41+
// step when running `zig build`).
42+
b.installArtifact(exe);
43+
44+
// This *creates* a Run step in the build graph, to be executed when another
45+
// step is evaluated that depends on it. The next line below will establish
46+
// such a dependency.
47+
const run_cmd = b.addRunArtifact(exe);
48+
49+
// By making the run step depend on the install step, it will be run from the
50+
// installation directory rather than directly from within the cache directory.
51+
// This is not necessary, however, if the application depends on other installed
52+
// files, this ensures they will be present and in the expected location.
53+
run_cmd.step.dependOn(b.getInstallStep());
54+
55+
// This allows the user to pass arguments to the application in the build
56+
// command itself, like this: `zig build run -- arg1 arg2 etc`
57+
if (b.args) |args| {
58+
run_cmd.addArgs(args);
59+
}
60+
61+
// This creates a build step. It will be visible in the `zig build --help` menu,
62+
// and can be selected like this: `zig build run`
63+
// This will evaluate the `run` step rather than the default, which is "install".
64+
const run_step = b.step("run", "Run the app");
65+
run_step.dependOn(&run_cmd.step);
66+
67+
// Creates a step for unit testing. This only builds the test executable
68+
// but does not run it.
69+
const lib_unit_tests = b.addTest(.{
70+
.root_source_file = b.path("src/root.zig"),
71+
.target = target,
72+
.optimize = optimize,
73+
});
74+
75+
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
76+
77+
const exe_unit_tests = b.addTest(.{
78+
.root_source_file = b.path("src/main.zig"),
79+
.target = target,
80+
.optimize = optimize,
81+
});
82+
83+
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
84+
85+
// Similar to creating the run step earlier, this exposes a `test` step to
86+
// the `zig build --help` menu, providing a way for the user to request
87+
// running the unit tests.
88+
const test_step = b.step("test", "Run unit tests");
89+
test_step.dependOn(&run_lib_unit_tests.step);
90+
test_step.dependOn(&run_exe_unit_tests.step);
91+
}

zig/build.zig.zon

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
.{
2+
// This is the default name used by packages depending on this one. For
3+
// example, when a user runs `zig fetch --save <url>`, this field is used
4+
// as the key in the `dependencies` table. Although the user can choose a
5+
// different name, most users will stick with this provided value.
6+
//
7+
// It is redundant to include "zig" in this name because it is already
8+
// within the Zig package namespace.
9+
.name = "zig",
10+
11+
// This is a [Semantic Version](https://semver.org/).
12+
// In a future version of Zig it will be used for package deduplication.
13+
.version = "0.0.0",
14+
15+
// This field is optional.
16+
// This is currently advisory only; Zig does not yet do anything
17+
// with this value.
18+
//.minimum_zig_version = "0.11.0",
19+
20+
// This field is optional.
21+
// Each dependency must either provide a `url` and `hash`, or a `path`.
22+
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
23+
// Once all dependencies are fetched, `zig build` no longer requires
24+
// internet connectivity.
25+
.dependencies = .{
26+
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
27+
//.example = .{
28+
// // When updating this field to a new URL, be sure to delete the corresponding
29+
// // `hash`, otherwise you are communicating that you expect to find the old hash at
30+
// // the new URL.
31+
// .url = "https://example.com/foo.tar.gz",
32+
//
33+
// // This is computed from the file contents of the directory of files that is
34+
// // obtained after fetching `url` and applying the inclusion rules given by
35+
// // `paths`.
36+
// //
37+
// // This field is the source of truth; packages do not come from a `url`; they
38+
// // come from a `hash`. `url` is just one of many possible mirrors for how to
39+
// // obtain a package matching this `hash`.
40+
// //
41+
// // Uses the [multihash](https://multiformats.io/multihash/) format.
42+
// .hash = "...",
43+
//
44+
// // When this is provided, the package is found in a directory relative to the
45+
// // build root. In this case the package's hash is irrelevant and therefore not
46+
// // computed. This field and `url` are mutually exclusive.
47+
// .path = "foo",
48+
49+
// // When this is set to `true`, a package is declared to be lazily
50+
// // fetched. This makes the dependency only get fetched if it is
51+
// // actually used.
52+
// .lazy = false,
53+
//},
54+
},
55+
56+
// Specifies the set of files and directories that are included in this package.
57+
// Only files and directories listed here are included in the `hash` that
58+
// is computed for this package. Only files listed here will remain on disk
59+
// when using the zig package manager. As a rule of thumb, one should list
60+
// files required for compilation plus any license(s).
61+
// Paths are relative to the build root. Use the empty string (`""`) to refer to
62+
// the build root itself.
63+
// A directory listed here means that all files within, recursively, are included.
64+
.paths = .{
65+
"build.zig",
66+
"build.zig.zon",
67+
"src",
68+
// For example...
69+
//"LICENSE",
70+
//"README.md",
71+
},
72+
}

zig/src/main.zig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const std = @import("std");
2+
3+
pub fn main() !void {
4+
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
5+
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
6+
7+
// stdout is for the actual output of your application, for example if you
8+
// are implementing gzip, then only the compressed bytes should be sent to
9+
// stdout, not any debugging messages.
10+
const stdout_file = std.io.getStdOut().writer();
11+
var bw = std.io.bufferedWriter(stdout_file);
12+
const stdout = bw.writer();
13+
14+
try stdout.print("Run `zig build test` to run the tests.\n", .{});
15+
16+
try bw.flush(); // don't forget to flush!
17+
}
18+
19+
test "simple test" {
20+
var list = std.ArrayList(i32).init(std.testing.allocator);
21+
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
22+
try list.append(42);
23+
try std.testing.expectEqual(@as(i32, 42), list.pop());
24+
}

zig/src/root.zig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const std = @import("std");
2+
const testing = std.testing;
3+
4+
export fn add(a: i32, b: i32) i32 {
5+
return a + b;
6+
}
7+
8+
test "basic add functionality" {
9+
try testing.expect(add(3, 7) == 10);
10+
}

0 commit comments

Comments
 (0)