My blog containing blog posts (duh…) and additional materials from courses at fi in which I've been involved in one way or another
Find a file
Matej Focko 957962665d
algorithms(avl): refactor code
Signed-off-by: Matej Focko <me@mfocko.xyz>

diff --git a/static/files/algorithms/rb-trees/avl/src/AVL.cs b/static/files/algorithms/rb-trees/avl/src/AVL.cs
index 757d8d4..9b3e35e 100644
--- a/static/files/algorithms/rb-trees/avl/src/AVL.cs
+++ b/static/files/algorithms/rb-trees/avl/src/AVL.cs
@@ -12,32 +12,29 @@ class AVL<T>(IComparer<T> comparator) : IEnumerable<T> {

     #region AVLSpecific

-    private static (bool correct, int depth) Check(Node<T>? node, int depth) {
+    private static (bool Correct, int Depth) Check(Node<T>? node, int depth) {
         if (node == null) {
             return (true, depth);
         }

-        var (leftCorrect, leftDepth) = Check(node.Left, 1 + depth);
-        if (!leftCorrect) {
-            return (false, leftDepth);
+        var left = Check(node.Left, 1 + depth);
+        if (!left.Correct) {
+            return (false, left.Depth);
         }

-        var (rightCorrect, rightDepth) = Check(node.Right, 1 + depth);
+        var right = Check(node.Right, 1 + depth);

-        var foundDepth = Math.Max(leftDepth, rightDepth);
-        return (rightCorrect && Math.Abs(leftDepth - rightDepth) <= 1, foundDepth);
+        var foundDepth = Math.Max(left.Depth, right.Depth);
+        return (right.Correct && Math.Abs(left.Depth - right.Depth) <= 1, foundDepth);
     }

-    public bool IsCorrect() {
-        var (correct, _) = Check(_root, 0);
-        return correct;
-    }
+    public bool IsCorrect() => Check(_root, 0).Correct;

-    private void InsertRebalance(List<Node<T>> nodes) {
+    private void InsertRebalance(List<Node<T>> nodes, T item) {
         // TODO
     }

-    private void DeleteRebalance(List<Node<T>> nodes) {
+    private void DeleteRebalance(List<Node<T>> nodes, T item) {
         // TODO
     }

@@ -79,10 +76,9 @@ class AVL<T>(IComparer<T> comparator) : IEnumerable<T> {
         } else {
             path[lastIdx].Left = newItem;
         }
-        path.Add(newItem);

         // rebalance
-        InsertRebalance(path);
+        InsertRebalance(path, item);
         return true;
     }
2024-02-04 13:58:41 +01:00
.github/workflows ci: enable on ‹trunk› and merging to ‹trunk› 2024-01-06 17:20:55 +01:00
algorithms algorithms(avl): add WIP 2024-02-04 13:58:41 +01:00
automata feat: don't reference FI MU subjects by their codes 2023-11-24 16:30:23 +01:00
blog blog(rust-opinion): fix colloquial 2024-02-04 13:58:19 +01:00
c feat: don't reference FI MU subjects by their codes 2023-11-24 16:30:23 +01:00
cpp cpp: add categories 2024-01-29 12:46:54 +01:00
foundations feat: don't reference FI MU subjects by their codes 2023-11-24 16:30:23 +01:00
functional feat: don't reference FI MU subjects by their codes 2023-11-24 16:30:23 +01:00
src fix(contributions): use HTML tag instead of markdown 2024-01-29 12:46:54 +01:00
static algorithms(avl): refactor code 2024-02-04 13:58:41 +01:00
.gitignore chore: run pre-commit 2024-01-03 19:38:35 +01:00
.gitlab-ci.yml fix: build 2023-09-06 18:37:15 +02:00
.pre-commit-config.yaml chore: update pre-commit 2024-01-03 19:31:11 +01:00
babel.config.js chore: transfer all KBs to single one 2022-11-05 15:25:15 +01:00
docusaurus.config.js chore: switch light theme to One Light 2024-02-04 13:48:45 +01:00
makefile chore: do not recreate assets on each ‹make dev› 2024-02-03 22:33:31 +01:00
package.json chore: yarn upgrade 2024-01-29 12:46:54 +01:00
README.md chore: transfer all KBs to single one 2022-11-05 15:25:15 +01:00
regenerate-archives.sh chore: run pre-commit 2024-01-03 19:38:35 +01:00
regenerate-dots.sh revert: "fix: switch graphviz to pngs as it is unusable now" 2023-09-07 17:59:11 +02:00
sidebars.js chore: transfer all KBs to single one 2022-11-05 15:25:15 +01:00
yarn.lock chore: yarn upgrade 2024-01-29 12:46:54 +01:00

Website

This website is built using Docusaurus 2, a modern static website generator.

Installation

$ yarn

Local Development

$ yarn start

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

Build

$ yarn build

This command generates static content into the build directory and can be served using any static contents hosting service.

Deployment

Using SSH:

$ USE_SSH=true yarn deploy

Not using SSH:

$ GIT_USER=<Your GitHub username> yarn deploy

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the gh-pages branch.