[{"content":"This post is about the $f$-array data structure, which was introduced by Prasad Jayanti in f-arrays: implementation and applications (PODC 2002).\nWhat is it? An $f$-array is a data structure that can be thought of as similar to a regular array, except it provides a read() operation. This read operation returns the value of some function $f$ applied to the whole array.\nFurthermore, the types of the elements in the array need not be the same, so a mental model I have for the array is something like the following:\ntemplate\u0026lt;typename T_1, typename T_2, ..., typename T_m\u0026gt; struct F_Array { std::tuple\u0026lt;T_1, T_2, ..., T_m\u0026gt; array; }; However, in practice it is most likely the case that the array is useful if the types are the same (that is, $T_1 = T_2 = \\dots = T_m$).\nFirst let\u0026rsquo;s go over the API they introduced:\n// applies op to the i\u0026#39;th element of the array. void update(op, i); // computes some function f on the whole array. (Assume f returns a value of type T) T read(); Examples \u0026amp; Applications So let\u0026rsquo;s give some examples of problems we can solve with an $f$-array.\n1. The Max/Min of an Array Suppose we have an array and we wish to compute the max of the values in that array. Here we set:\n$$f(A_1, A_2, \\dots, A_m) = \\max(A_1, A_2, \\dots, A_m)$$\nNote: Technically, the above notation isn\u0026rsquo;t super precise since it implies we have at least elements $1$ and $2$, but I think it\u0026rsquo;s easier to process than $\\max_{i \\in {1, \\dots, m}} A_i$, and it gets the point across.\nAnd we let all the elements of the array be integers.\nThat way read() returns the max of the array, and update(op, i) applies op to the integer at index i (op can be an increment, replacing the value, etc.).\nSame case for min—just swap max with min.\n2. Multi-Writer Snapshot Array In case you don\u0026rsquo;t know, a multi-writer snapshot array is an array where multiple threads can concurrently write to any index i, and any thread can take a snapshot of the array at the time (this is usually called a scan).\nTo build this with an $f$-array, simply set $f$ as\n$$f(A_1, A_2, \\dots, A_m) = (A_1, A_2, \\dots, A_m)$$\nThen update(write(v), i) writes v to index i, and read() returns a consistent snapshot of all $m$ elements at once.\nImplementing an $f$-Array In this section, we go over optimizing a simple naive implementation all the way to the one presented in the paper. Similar to the Lazy List post (I think these sections are pretty fun lol).\n1. Lock-Based $f$-Array Alright, let\u0026rsquo;s start with the simplest possible implementation. Slap a lock around everything.\nT read() { lock(); for (int j = 1; j \u0026lt;= m; j++) { v_j = read(A_j); } T res = f(v_1, v_2, ..., v_m); unlock(); return res; } void update(op, i) { lock(); A_i = op(A_i); unlock(); } In the above code, a read() takes $O(m)$ time to run. There\u0026rsquo;s a clear optimization we can do if we want the read() to be fast. We can cache it, just put a lot of the overhead on update.\nT read() { return cached; } void update(op, i) { lock(); A_i = op(A_i); for (int j = 1; j \u0026lt;= m; j++) { v_j = read(A_j); } cached = f(v_1, v_2, ..., v_m); unlock(); } Assuming cached is read and written atomically, read() is now $O(1)$ and even wait-free! Every read() just returns the latest cached value, while update() takes $O(m)$ time.\n2. Lock-Freedom Locks aren\u0026rsquo;t very scalable. When there\u0026rsquo;s a lot of contention, each thread needs to wait in a line to obtain the lock. Thus, let\u0026rsquo;s liberate ourselves from locks!\nTo do this, we first introduce the concept of LL/SC.\nLL/SC (Load-Linked / Store-Conditional) Here is a brief summary of how (idealized) LL/SC works:\nLL(x) reads the current value of x and starts \u0026ldquo;watching\u0026rdquo; it. SC(x, val) attempts to store val into x, returning true if it succeeds and false otherwise. The catch is that SC(x, val) only succeeds if no other thread has successfully executed SC on x since this thread\u0026rsquo;s LL(x).\nIf another thread sneaks in a successful SC in between, our SC does nothing and returns false.\nBelow is a diagram which should explain what I mean. (I had Gemini generate this diagram from my beautiful ASCII 😌)\nThread 1: LL(x) ──────────────────────► SC(x, v1) ✗ fails ▲ │ breaks T1\u0026#39;s link Thread 2: LL(x) ──────────► SC(x, v2) ✓ succeeds Lock-free Update We can use LL/SC to make our update() function lock-free. You might wonder why we can\u0026rsquo;t just use a CAS instead, and the reason for that is the ABA problem (see the Appendix below for the explanation).\nSo the idea is simple: once we have atomically committed our change to $A_i$, we need to ensure that cached reflects it. We do this by introducing a function refresh() which \u0026ldquo;refreshes\u0026rdquo; cached so that it sees our update on $A_i$.\nbool refresh() { LL(cached); for (int j = 1; j \u0026lt;= m; j++) { v_j = read(A_j); } return SC(cached, f(v_1, v_2, ..., v_m)); } T read() { return cached; } void update(op, i) { A_i = op(A_i); while (!refresh()) { // someone else updated cached while we were scanning, retry! } } We wrap refresh in a retry loop to ensure that cached is calculated with our updated $A_i$.\nThe reason for the retry is for the case of a concurrent update. When a concurrent update occurs, it might\u0026rsquo;ve read $A_i$ before our update occurred. How do we know when cached is calculated with our value? Well we know for certain that if we run SC ourselves, then it used our updated $A_i$ value since we read our updated $A_i$ in refresh(). Hence, we stop the retry when the SC succeeded.\n3. Wait-Freedom Lock-free is nice, but an unlucky thread could theoretically get stuck retrying the while (!refresh()) loop forever if other threads keep beating it to SC(cached).\nIs there a way to improve it? Well, we\u0026rsquo;re in luck cause the paper introduced this one weird trick (readers hate him for this one trick):\nRefresh at most TWICE.\nvoid update(op, i) { A_i = op(A_i); if (!refresh()) { refresh(); } } Wait\u0026hellip; why is calling refresh() twice enough? For this, I\u0026rsquo;ll give a short proof:\nProof:\nFirst, we know that no two successful refresh() are concurrent. This is because the later SC will fail causing the refresh associated with that SC to fail. Keep this in mind for later.\nTrivial Case: If either of our refresh() calls succeeds, then cached was computed using our updated $A_i$ (or a newer value).\nIf both refreshes fail: For our first refresh() to fail, some other refresh() (call it $S_1$) must have executed a successful SC after our first refresh() started its LL.\nFor our second refresh() to fail, another refresh() (call it $S_2$) must have executed a successful SC during our second refresh().\nBecause $S_1$ and $S_2$ both succeeded, $S_2$\u0026rsquo;s LL must have occurred after $S_1$\u0026rsquo;s SC (otherwise $S_1$ would have invalidated $S_2$). Since our first refresh() is concurrent with $S_1$, then $S_2$ occurred after our first refresh which is after we updated $A_i$.\nThus $S_2$ has read our updated value of $A_i$, essentially helping us complete our propagation. QED.\n4. Turning It Into a Tree Great, so that\u0026rsquo;s it right? Well kind of\u0026hellip; The paper made another observation. They realized that most functions $f$ are decomposable (not sure if that\u0026rsquo;s the correct term lol). But essentially, this property:\n$$f(a, b, c, d) = f(f(a,b), f(c,d))$$\nWith this in mind, they came up with the following idea. Hey we can make our array a tree where each subtree is an $f$-array.\nIn fact, our previous implementation is also a tree. Just a very short one, in which root is the variable cached in our code before.\ngraph TB root((root))--\u0026gt;A1((A_1)) root--\u0026gt;A2((A_2)) root--\u0026gt;A3((A_3)) root--\u0026gt;A4((A_4)) See it\u0026rsquo;s a very short tree, why don\u0026rsquo;t we make it taller!\ngraph TB root((root))--\u0026gt;l1((C_1)) root--\u0026gt;l2((C_2)) l1--\u0026gt;A1((A_1)) l1--\u0026gt;A2((A_2)) l2--\u0026gt;A3((A_3)) l2--\u0026gt;A4((A_4)) Notice that you can think of each of C_1 and C_2 as its own smaller $f$-array. Same with the root node where C_1 and C_2 are the elements of that array. This is also why the decomposable property I mentioned matters!\nTo adapt our code to a balanced binary tree, refresh(node) now only reads a node\u0026rsquo;s two children instead of scanning all $m$ leaves, and update() walks up the tree from the leaf leaf(i) to root (read() simply loads the value at root):\nbool refresh(Node* node) { LL(node-\u0026gt;val); T left = node-\u0026gt;left-\u0026gt;val; T right = node-\u0026gt;right-\u0026gt;val; return SC(node-\u0026gt;val, f(left, right)); } void update(op, i) { A_i = op(A_i) Node* curr = leaf(i); while (curr != root) { curr = parent(curr); if (!refresh(curr)) { refresh(curr); } } } Because update() only traverses one root-to-leaf path and each refresh() reads just two children, our runtime is much faster! Assuming a balanced binary tree and an $O(1)$ function $f$, update() now takes $O(\\log m)$ time.\nAs an aside, we can also introduce a get(i) API which returns the element at index i. This isn\u0026rsquo;t mentioned in the paper, but it seems pretty simple to add:\nT get(i) { T res = A_i; Node* curr = leaf(i); while (curr != root) { curr = parent(curr); if (!refresh(curr)) { refresh(curr); } } return res; } Note, we cannot just return $A_i$ directly, because this would cause a linearization bug. In fact, let\u0026rsquo;s segue into that!\nCorrectness Let\u0026rsquo;s show that the data structure is linearizable. We can do this by specifying the linearization points.\nFor read() the linearization point is simply the time we read the root node.\nFor update() the linearization point is when our value has propagated all the way to root. The paper describes this in more detail, but the gist of it is that once $A_i$\u0026rsquo;s value is read and propagated up to root. Whether this is done by another thread\u0026rsquo;s refresh() or ourselves, we linearize there. (If another update overwrites $A_i$ before our value ever reaches root, our update linearizes right before that overwriting update\u0026rsquo;s value reaches root.)\nSimilarly, the get(i) API we introduced has the same linearization point as update(). We can\u0026rsquo;t just return $A_i$ directly without propagating it up to root: if we did, a subsequent read() that starts after get(i) returns could still see the stale root value from before $A_i$ was propagated, violating linearizability.\nAppendix Feel free to stop reading. I\u0026rsquo;m adding this section as a nice-to-know.\nWhy we need LL/SC and why a CAS is not enough. The main issue is the ABA problem. Suppose we use a CAS that compares the old value of cached and swaps it with a new one.\nSomething like CAS(cached, old_cached, val). Here\u0026rsquo;s a counterexample: suppose $A = [0, 0]$ and $f = \\max$, so initially cached = 0.\nThread 1 calls update(set(0), 2). It writes $A_2 = 0$, reads old_cached = 0, and then gets paused by the OS. Thread 2 sets $A_1 = 10$ and updates cached = 10. Thread 1 wakes up, scans $A = [10, 0]$, computes val = 10, and pauses again before its CAS. Thread 2 runs another update, setting $A_1 = 0$ (so $A = [0, 0]$) and updating cached = 0, then finishes. Thread 1 finally wakes up and executes CAS(cached, 0, 10). Because cached is 0 again (matching old_cached), the CAS succeeds (ABA!) and writes 10 to cached. Causing read() to return 10 even though $A = [0, 0]$. I\u0026rsquo;d make an animation for this, but I\u0026rsquo;m kinda lazy rn\u0026hellip;\n","permalink":"http://blog.brianmoniaga.com/posts/f_array/","summary":"\u003cp\u003eThis post is about the $f$-array data structure, which was introduced by Prasad\nJayanti in \u003ca href=\"https://dl.acm.org/doi/pdf/10.1145/571825.571875\"\u003ef-arrays: implementation and applications\u003c/a\u003e (PODC 2002).\u003c/p\u003e\n\u003ch1 id=\"what-is-it\"\u003eWhat is it?\u003c/h1\u003e\n\u003cp\u003eAn $f$-array is a data structure that can be thought of as similar to a\nregular array, except it provides a \u003ccode\u003eread()\u003c/code\u003e operation.\nThis read operation returns the value of some function $f$ applied to the whole array.\u003c/p\u003e\n\u003cp\u003eFurthermore, the types of the elements in the array need not be the same, so\na mental model I have for the array is something like the following:\u003c/p\u003e","title":"f-Arrays for Noobs."},{"content":"This is the first post in which I go over random concurrent data structures.\nThis post is based on the Lazy List data structure introduced here: https://people.csail.mit.edu/shanir/publications/Lazy_Concurrent.pdf\nIdeally this post can help you understand at a high level how we can optimize a regular set data structure and eventually end up with the one described in the paper.\nWhat is it? The data structure presented in the paper is known as the Lazy List. It functions like a regular sequential set in which as a user you can call the following APIs:\nadd(x) -\u0026gt; bool - Inserts x into the set. remove(x) -\u0026gt; bool - Removes x from the set. contains(x) -\u0026gt; bool - Checks if x is in the set. It is also thread-safe, meaning multiple threads can access the data structure and it would work correctly! (We will talk more about what it means to be \u0026ldquo;correct\u0026rdquo; below)\nSo what makes this data structure special?\nA question that you might be asking right now is \u0026ldquo;why not just wrap a set in a lock and call it a day?\u0026rdquo;. And you are right to be questioning that!\nBefore jumping into the presented data structure, let\u0026rsquo;s build up to it step by step.\nLinked List Based Set. We start with a sorted singly linked list. Each node in the list represents an element in our set.\n\u0026ldquo;Wait, why a linked list? Wouldn\u0026rsquo;t you normally use a hash set?\u0026rdquo; Yeah\u0026hellip; we\u0026rsquo;re mostly using a linked list here for the sake of introducing the lazy list as it is based off a linked list.\nBelow shows how our list with the values {1, 3, 7, 8, 67} would look like:\nflowchart LR H[\u0026#34;1\u0026#34;] --\u0026gt; A[\u0026#34;3\u0026#34;] A --\u0026gt; B[\u0026#34;7\u0026#34;] B --\u0026gt; C[\u0026#34;8\u0026#34;] C --\u0026gt; T[\u0026#34;67\u0026#34;] Implementing each operation is simple:\nThe add(x) operation traverses the list and finds where to insert a new node and inserts it.\nThe remove(x) operation traverses the list and finds if x is present, removing the node if present.\nThe contains(x) operation simply traverses the list to find if x is present or not.\nTo make this data structure thread-safe, we simply have a big global lock and lock before each operation and release it after the operation is done.\nCan we make this faster? Of course we can, otherwise this post wouldn\u0026rsquo;t exist. One bottleneck with this locking approach is that each operation must wait for the lock. This is bad because all operations use the same lock. So each operation must wait for the other to finish and release the lock before it being able to do work.\nIn a theoretical worst case scenario, it\u0026rsquo;s possible the thread holding the lock keeps on getting yielded and therefore making all other concurrent operations wait longer.\nSo if we can make each operation not wait on the same lock, this issue is mitigated.\nFine Grained Locking (Optimistic List) One observation you might notice with sorted lists is that adding and removing only requires modifying a few nodes.\nTo show what I mean, consider the following list:\nflowchart LR H[\u0026#34;1\u0026#34;] --\u0026gt; A[\u0026#34;3\u0026#34;] A --\u0026gt; B[\u0026#34;7\u0026#34;] B --\u0026gt; C[\u0026#34;8\u0026#34;] C --\u0026gt; T[\u0026#34;67\u0026#34;] In the diagram above, when we want to:\nadd(6): We only need to touch the nodes 3 and 7. remove(7): We only need to touch the nodes 3 and 7. Let\u0026rsquo;s denote the nodes 3 and 7 here as pred and curr respectively to make things easier in the next sections.\nIf we lock only the nodes that matter (curr and pred), then we can improve the set\u0026rsquo;s performance, since we don\u0026rsquo;t have to wait for the global lock.\nNaively doing this however, is dangerous. During our traversal, if we don\u0026rsquo;t hold a global lock the list itself might have changed!\nTo see what I mean, observe the following video:\nYour browser does not support the video tag. But if we hold a global lock during the traversal, we go back to the performance of our first approach. To cope with this, once we hold the fine-grained lock, we should validate that nothing has changed.\nPrior to holding the lock, the following cases might have occured:\ncurr node could have been removed pred node could have been removed Another entry was inserted in between curr and pred. If the validation failed (one of the cases above was violated), then we simply restart the operation.\nNote: A case I was wondering was when curr-\u0026gt;next is modified? This is not a problem since curr-\u0026gt;next requires locking curr, which we already hold (and any earlier update is already visible to us).\nIn a hand-wavy pseudocode, here is how we can write our code:\nbool add(x) { while (true) { auto [pred, curr] = traverse(x); lock_guard(pred); // unlocks automatically at end of scope lock_guard(curr); if (validate(pred, curr)) { // same logic as seq. based } } } bool remove(x) { while (true) { auto [pred, curr] = traverse(x); lock_guard(pred); lock_guard(curr); if (validate(pred, curr)) { // same logic as seq. based } } } bool contains(x) { while (true) { auto [pred, curr] = traverse(x); lock_guard(pred); lock_guard(curr); if (validate(pred, curr)) { return curr.key == x; } } } How does validate work? To validate that the two nodes are still valid (that is, neither node has been deleted nor has a node been inserted between them), a simple approach is to re-traverse from head until we reach pred (proving pred is still reachable in the list), and then check pred.next == curr:\nbool validate(pred, curr) { Node* node = head; while (node.key \u0026lt;= pred.key) { if (node == pred) { return pred.next == curr; } node = node.next; } return false; } This means we have to retraverse the list (though we don\u0026rsquo;t need to use locks)\nCan we make this faster? Yes we can!!!\nWhen using sets, contains() is usually the most common operation used by far. So if we can make contains() not lock at all (lock-free) and potentially have no retries (wait-free) then this will be blazingly fast!\nThe Lazy List The Lazy List (the data structure in the paper) is based off the Optimistic List, except its contains operation is wait-free!\nThe trick is to add a logical deletion step (marking a node as deleted) before actually doing the physical deletion (updating the pointers).\nEssentially each node should have an atomic boolean marked which states whether the node has been \u0026ldquo;removed\u0026rdquo; yet. The remove(x) operation should then set curr.marked = true when it\u0026rsquo;s trying to delete a node.\nflowchart LR subgraph Step 1: Logical Deletion D1[\u0026#34;1\u0026#34;] --\u0026gt; A1[\u0026#34;3\u0026#34;] A1 --\u0026gt; B1[\u0026#34;7 (marked: true)\u0026#34;] B1 --\u0026gt; C1[\u0026#34;8\u0026#34;] end flowchart LR subgraph Step 2: Physical Deletion D2[\u0026#34;1\u0026#34;] --\u0026gt; A2[\u0026#34;3\u0026#34;] A2 --\u0026gt; C2[\u0026#34;8\u0026#34;] B2[\u0026#34;7 (marked: true)\u0026#34;] -.-\u0026gt; C2 end A nice bonus is that marked makes validate(pred, curr) for add and remove go from an $O(N)$ operation to $O(1)$ since we don\u0026rsquo;t have to re-traverse the list to see if the nodes have been deleted:\nbool validate(pred, curr) { return !pred.marked \u0026amp;\u0026amp; !curr.marked \u0026amp;\u0026amp; pred.next == curr; } The main improvement, however, is that contains(x) requires no locks and no retries:\nbool contains(x) { curr = traverse(x); // no locks, no validation! return curr.key == x \u0026amp;\u0026amp; !curr.marked; } Right now, you might be skeptical about the statement I just made about it requiring no lock and no retries. So let\u0026rsquo;s go into the correctness of this.\nCorrectness So how do you determine what is \u0026ldquo;correct\u0026rdquo;? The standard of correctness for concurrent data structures is a condition called linearizability.\nLinearizability Linearizability is a condition in which between each operation\u0026rsquo;s invocation and response, there exists a point (call this a linearization point) in which the operation appears to take effect instantaneously at that point (and respects the real-time order of non-overlapping operations).\nWhy does linearizability matter? It means if we take these linearization points and replay them on a regular sequential set, it ends up in the exact same state as our concurrent Lazy List.\nLazy List is Linearizable Let\u0026rsquo;s now provide some reasoning as to how the lazy list is linearizable.\nFor successful add and remove operations, every other thread can see that the operation has succeeded when the node is linked into the list (for add) or when marked is set to true (for remove). So those are their linearization points. Unsuccessful add and remove calls linearize when they observe curr after validation.\nNow for contains. Suppose we are traversing the list. If in the middle of a traversal:\nThe current node we are visiting has been deleted: This is fine because the deleted node\u0026rsquo;s next still points to a valid node of our list. If we have landed on curr, and another thread just deleted this node, then the marked tag has been set to true, thus we return that the item is no longer there. Suppose we are in the middle of a traversal and a concurrent add(x) creates a new node at a place earlier than curr. Then there exists a point in time in which the add(x) had not occurred yet-we can linearize there! Sequentially, this means contains(x) finished before add(x). And if add(x) had already finished before contains(x) started, the node would already be in the list from the start of our traversal, so we are guaranteed to find it.\nEnd I think this is a good place for me to stop yapping. I\u0026rsquo;m not a good writer yet, so hopefully I get better the more I write. I find that writing helps me think clearer and helps me understand the concepts better (perhaps since it\u0026rsquo;s similar to rubber ducking).\nI will try to keep making these data structure posts since I am forced to read these papers as part of my thesis anyways. So I think making these short posts is helpful for my understanding. Also there isn\u0026rsquo;t much resources online about these things which is a shame since its quite cool.\nThere is 1 more data structure I plan on writing about which is a non-blocking binary tree (Ellen tree). So that might be the next post :D\n","permalink":"http://blog.brianmoniaga.com/posts/lazy_list/","summary":"\u003cp\u003eThis is the first post in which I go over random concurrent data structures.\u003c/p\u003e\n\u003cp\u003eThis post is based on the Lazy List data structure introduced here:\n\u003ca href=\"https://people.csail.mit.edu/shanir/publications/Lazy_Concurrent.pdf\"\u003ehttps://people.csail.mit.edu/shanir/publications/Lazy_Concurrent.pdf\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003eIdeally this post can help you understand at a high level how we can optimize a regular\nset data structure and eventually end up with the one described in the paper.\u003c/p\u003e\n\u003ch1 id=\"what-is-it\"\u003eWhat is it?\u003c/h1\u003e\n\u003cp\u003eThe data structure presented in the paper is known as the Lazy List.\nIt functions like a regular sequential set in which as a user you can call\nthe following APIs:\u003c/p\u003e","title":"Lazy List for Noobs."},{"content":"I have been reading through my past writings and I realized how terrible of a writer I am. Therefore, I will start clean and start putting in more effort in my writings.\nHopefully I can improve my thought process the more I write. I find that writing tends to help me think clearer, and it clears a lot of the gaps in my knowledge that I didn\u0026rsquo;t knew existed.\nAnyways, I also need a topic to start writing about. One idea I am thinking off is to make writeups about concurrent data structures I have to know off as part of my undergrad thesis. This is probably the best approach for now, as most of the topics are novel to me, so it can clear up a lot of my knowledge gaps.\n","permalink":"http://blog.brianmoniaga.com/posts/rewrite/","summary":"\u003cp\u003eI have been reading through my past writings and I realized how\nterrible of a writer I am. Therefore, I will start clean and start\nputting in more effort in my writings.\u003c/p\u003e\n\u003cp\u003eHopefully I can improve my thought process the more I write. I find\nthat writing tends to help me think clearer, and it clears a lot of\nthe gaps in my knowledge that I didn\u0026rsquo;t knew existed.\u003c/p\u003e\n\u003cp\u003eAnyways, I also need a topic to start writing about. One idea I am\nthinking off is to make writeups about concurrent data structures I\nhave to know off as part of my undergrad thesis. This is probably\nthe best approach for now, as most of the topics are novel to me, so\nit can clear up a lot of my knowledge gaps.\u003c/p\u003e","title":"Cleaning up this site."},{"content":"This Post was Last Updated on: June 8, 2024\nSTEP-Writer is just my own take on writing a text editor, my hope is that as I continue working on this project it will eventually reach the point where I myself would use this application as my go to editor. Additionally, I wish to have this text editor work as a multi-user editor, this means that changes in the application is synced across various users.\nThis page ideally would be the final \u0026ldquo;documentation\u0026rdquo; page for this project. I will try to keep this page up to date with all the recent updates that I make to the repository.\nAcronyms. As mentioned, my goal is to make this program good enough to be my go to editor.\nCurrently, STEP is an acronym that\u0026rsquo;s supposed to be Shared Text Editor Program. But at this stage it\u0026rsquo;s looking more like Scuffed Text Editor Program. Therefore, I will try my best, such that I can finally transition from Scuffed $\\to$ Shared.\nOverview. STEP-Writer is a TUI text editor written in C++. At its core, its my own version of neovim, a tool that I spend a lot of time playing with the config files.\nUnfortunately, I can\u0026rsquo;t seem to connect neovim to my school\u0026rsquo;s remote servers as I can\u0026rsquo;t figure out a way to ssh within neovim nor was I able to install neovim in the remote servers. As the remote servers is important to ssh on\nHere is some old demo of the application in action (Current one needs to fix highlighting). Background: While this project might not be the next VS Code killer nor would it replace neovim, I think there\u0026rsquo;s some pedagogical values that can be attained working on this project. Moreover, since I am writing this myself I need not conform to any specific norms that some might have in their editors. This means that I am able to customize the crap out of my editor with either the weirdest keybindings that might not make sense to most but makes perfect sense to me.\nFeatures Currently this application features some basic text editing functionalities such as\nNormal Mode (Vim-like navigation using h j k l) Insert Mode (i) Status bar File explorer Saving and Quitting (CTRL + P) only when file is modified. Syntax Highlighting (Kinda, I need to update the vectors everytime first.) I haven\u0026rsquo;t outlined the details of these features quite well. As I am still working on improving these. Currently, I\u0026rsquo;m planning to refactor the codebase as after making several of these features work, it\u0026rsquo;s very surprising to see how much reading one\u0026rsquo;s own code can make yourself reflect on its quality.\nPlans Firstly, I have been working on various unit tests, I just got started on this so ideally once I finish writing these unit tests, I would have gotten a robust set of tests that I can be confident of when I start refactoring my horribly written program.\nThere are of course still various plans that I aim to make, the most important features that I aim to achieve quickly is a proper file explorer, file saving, syntax highlighting, a search feature and a working terminal.\nOther plans that I wish to add but does not seem like it would matter as much at this point is to swap out the data structure I am using. This post seems to contain crucial information that I can implement in this project, I am heavily leaning towards using gap buffers but at this point it might be best to complete all other core features before working on this feature.\nDev-logs? Thus far I have encountered so many challenges and weird bugs and it has been really fun to overcome these obstacles such as heap and stack allocation bugs (bugs caused by how the stack frame works and it\u0026rsquo;s interactions with using FTXUI), structuring proper code and how one might refactor.\nI will probably start writing more about these stories cause I think they are worthwhile to talk about as it will help me in expressing my thoughts regarding similar issues whether it be to others or myself.\nRepository: GitHub: https://github.com/BrianAnakPintar/step-writer/ ","permalink":"http://blog.brianmoniaga.com/posts/stepwriter/","summary":"\u003cp\u003eThis Post was Last Updated on: June 8, 2024\u003c/p\u003e\n\u003cp\u003e\u003ca href=\"https://github.com/BrianAnakPintar/step-writer/blob/main/Docs/ThemesStacked.png\"\u003e\u003cimg alt=\"Themes.png\" loading=\"lazy\" src=\"https://github.com/BrianAnakPintar/step-writer/blob/main/Docs/ThemesStacked.png?raw=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003eSTEP-Writer is just my own take on writing a text editor, my hope is that as I continue working on this project it will eventually reach the point where I myself would use this application as my go to editor. Additionally, I wish to have this text editor work as a multi-user editor, this means that changes in the application is synced across various users.\u003c/p\u003e","title":"STEP - WRITER."}]