Commit graph

190 commits

Author SHA1 Message Date
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
aa6f33feb5
algorithms(avl): add changes
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-02-04 13:58:41 +01:00
f46561653f
algorithms(avl): add WIP
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-02-04 13:58:41 +01:00
5728170a57
blog(rust-opinion): fix colloquial
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-02-04 13:58:19 +01:00
3f87535d86
chore: switch light theme to One Light
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-02-04 13:48:45 +01:00
8f57806142
chore: do not recreate assets on each ‹make dev›
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-02-03 22:33:31 +01:00
06a1e38851
blog: add the ‹rust-opinion›
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-29 12:46:54 +01:00
f7c4241a24
chore: yarn upgrade
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-29 12:46:54 +01:00
7c5962aa7e
fix(contributions): use HTML tag instead of markdown
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-29 12:46:54 +01:00
58783833a0
cpp: add categories
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-29 12:46:54 +01:00
acce2832e8
chore: yarn upgrade
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-29 12:46:48 +01:00
4ab2615a05
cpp(placeholders): fix the static analysis
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-06 21:12:33 +01:00
e881234412
algorithms(bf-to-astar): fix typos
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-06 17:28:16 +01:00
1930f0207c
ci: enable on ‹trunk› and merging to ‹trunk›
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-06 17:20:55 +01:00
2cf4a3efba
chore: run pre-commit
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 19:38:35 +01:00
e63dbba74a
chore: update pre-commit
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 19:31:11 +01:00
92c52677e9
chore: ignore VSCode
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 19:17:40 +01:00
Matej Focko
5549494f67
algorithms(paths): ‹BF to A*› (#13) 2024-01-03 15:12:35 +01:00
2d7ba03369
algorithms(bf-to-astar): add A*
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:09:41 +01:00
21aeeeb042
algorithms(bf-to-astar): factor out the heap and dirs
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:08:54 +01:00
5164a31ce2
algorithms(bf-to-astar): add Dijkstra
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:54 +01:00
6a857d8ccd
algorithms(bf-to-astar): fix typos
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:54 +01:00
39213f1536
algorithms(bf-to-astar): normalize the output
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:54 +01:00
a1f871ffb8
algorithms(bf-to-astar): mention time complexity in BF
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:53 +01:00
b048c6dc4f
algorithms(bf-to-astar): add headers to satisfy compilation
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:53 +01:00
fe89d4815f
algorithms(bf-to-astar): add reference to the sources
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:53 +01:00
858a96722b
algorithms(bf-to-astar): add BF
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:07:52 +01:00
d16eaafd97
algorithms(bf-to-astar): add intro
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-01-03 15:06:12 +01:00
Matej Focko
d99297a19c
algorithms: fix the last update in front matter (#12) 2023-12-31 00:44:37 +01:00
e6670a423d
algorithms: fix the last update in front matter
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-12-31 00:41:56 +01:00
Matej Focko
1b7d0b6199
algorithms: split the intro to DP to multiple posts (#11) 2023-12-28 18:53:44 +01:00
15cb70735b
chore: upgrade deps
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-12-28 18:40:58 +01:00
c9228cd709
algorithms: split the intro to DP to multiple posts
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-12-28 18:37:57 +01:00
Matej Focko
155fa9c741
Solution to the backtracking with Karel (#10) 2023-12-24 00:12:50 +01:00
acc0efc8e0
algorithms: add solution for Karel
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-12-24 00:09:50 +01:00
eb9515f905
algorithms: move Karel to its own directory
Signed-off-by: Matej Focko <me@mfocko.xyz>
2023-12-23 13:52:17 +01:00
Matej Focko
b8ae08bb37
Fix formatting of talks and add QEcamp23 (#9) 2023-11-29 16:18:44 +01:00
a7c23d361b
feat(talks): add QEcamp23
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-29 16:14:42 +01:00
081cd78fb7
fix: formatting of the talks
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-29 16:08:43 +01:00
Matej Focko
f5478a8af2
fix(algorithms): fix broken links to sources (#8) 2023-11-28 20:45:35 +01:00
9bac381fc7
fix(algorithms): fix broken links to sources
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-28 20:42:41 +01:00
Matej Focko
075b4a89ad
fix(algorithms): correct the heading level (#7) 2023-11-28 20:25:17 +01:00
585a3b0356
fix(algorithms): correct the heading level
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-28 20:16:37 +01:00
Matej Focko
dadb0d51f7
Publish “Breaking of the Hash Table” (#6) 2023-11-28 19:38:59 +01:00
6117d79454
fix(algorithms): reword some parts of breaking the hash table
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-28 19:32:38 +01:00
f2810936fa
fix(algorithms): don't include date in the slug
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-28 19:18:20 +01:00
2794519506
feat(algorithms): add Breaking of the Hash Table
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-28 17:23:44 +01:00
a581e9753f
feat: use github and dracula themes
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-25 21:49:46 +01:00
Matej Focko
3b7bf4e2c7
feat: switch theme to One* (#5) 2023-11-25 21:41:19 +01:00
00c31aeb7b
feat: switch theme to One*
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-25 21:37:44 +01:00