liangbm3 Blog

website·Indexed 31 days ago

https://liangbm3.site/

A technical blog featuring tutorials and notes on C++, Python, data structures and algorithms (including graph theory and binary trees), Linux system administration, ROS1, and computer fundamentals such as number systems and memory alignment.

Tokens
43.8K
Snippets
201
Records
265
Agent score
55%

What's inside liangbm3

  1. Overview of Topological Sorting

    Topological sorting is a linear ordering of vertices in a Directed Acyclic Graph (DAG). For every directed edge (u -> v), vertex u must come before vertex v in the ordering. It is primarily used to solve dependency and execution order problems, such as task scheduling (e.g., Makefiles), prerequisite course planning, and software package dependency management (e.g., apt-get).
  2. Overview of Single-Source Shortest Path (SSSP) Algorithms

    The Single-Source Shortest Path problem aims to find the shortest path from a specified source vertex to all other vertices in a weighted directed or undirected graph. Three primary algorithms are used depending on the graph's characteristics:

    1. Dijkstra's Algorithm: The most common and efficient choice, but requires all edge weights to be non-negative.
    2. Bellman-Ford Algorithm: More versatile than Dijkstra; it can handle negative edge weights and detect negative weight cycles.
    3. SPFA (Shortest Path Faster Algorithm): An optimized version of Bellman-Ford that is typically faster, especially for sparse graphs, and also handles negative weights and cycle detection.
  3. Overview of command-line argument types in argparse

    Python's argparse module supports three primary types of command-line arguments:

    1. Positional arguments: Required arguments provided in a specific order without prefixes (e.g., python main.py arg1 arg2).
    2. Optional arguments: Optional parameters starting with - or -- (e.g., python main.py --config config.yaml).
    3. Flag arguments: Special optional arguments that do not take a value and act as boolean switches (e.g., python main.py -v).
  4. Overview of Disjoint Set Union (DSU)

    Disjoint Set Union (DSU), also known as Union-Find, is a data structure used to efficiently manage a collection of non-overlapping sets. It supports two primary operations:

    • Find: Determines which set an element belongs to.
    • Union: Merges two distinct sets into a single larger set.
  5. SQLite3 C++ Core Concepts

    When using the SQLite3 API in C++, three core components are essential:

    1. sqlite3: A handle representing an open database connection. All operations require this handle.
    2. sqlite3_stmt: A handle representing a compiled (prepared) SQL statement, used for complex queries and preventing SQL injection.
    3. Return Codes: Most functions return an integer status code. Common codes include SQLITE_OK (success), SQLITE_ERROR (generic error), and SQLITE_BUSY (database locked).
  6. Understand Minimum Spanning Tree (MST) concepts

    A Minimum Spanning Tree (MST) is used in weighted undirected connected graphs. It is a subset of edges that connects all vertices in the graph without any cycles, while minimizing the total sum of edge weights.

    Key properties for constructing MSTs:

    • Cut Property: For any partition of vertices into two disjoint sets, the minimum weight edge crossing the cut must belong to some MST.
    • Cycle Property: For any cycle in the graph, the edge with the maximum weight in that cycle cannot belong to any MST.
  7. ROS Core Concepts Overview

    Understanding the basic building blocks of ROS:

    • Node: An independent process performing a specific task.
    • Topic: A named bus for asynchronous many-to-many communication (Publish/Subscribe).
    • Service: A synchronous request-response communication mechanism.
    • Message: The data structure used for communication between nodes.
    • Parameter Server: A global shared database for configuration parameters.
    • Package: The organizational unit for ROS code, containing nodes, libraries, and configs.
    • Workspace: The directory where packages are developed and compiled.
  8. Understand Quadcopter Command and Control Systems

    The control architecture consists of the following components:

    • Remote Controller & Receiver: Typically operates at 2.4GHz. Requires at least 4 channels for basic flight: Throttle, Yaw, Pitch, and Roll. Throttle can be 'Direct' (does not return to center) or 'Incremental' (spring-loaded to center).
    • Autopilot: Comprises a GPS receiver, IMU (3-axis accelerometer, 3-axis gyroscope, magnetometer), barometer, ultrasonic rangefinder, and a microcomputer. It handles Perception (where am I), Control (how to get there), and Decision (where to go).
    • Ground Control Station (GCS): Software used for mission planning, real-time monitoring, and flight log analysis.
    • Telemetry (Data Link): Provides bidirectional communication between the autopilot and GCS, typically using 433MHz or 915MHz frequencies and the MAVLink protocol.
  9. Understand the RAII programming paradigm in C++

    RAII (Resource Acquisition Is Initialization) is a C++ programming paradigm that binds the lifecycle of a resource to the lifecycle of an object. The core mechanism is:

    1. Acquisition: Resources are acquired in the object's constructor.
    2. Usage: Resources are used via the object's methods during its lifetime.
    3. Release: Resources are automatically released in the object's destructor when the object goes out of scope (e.g., function return, deletion, or stack unwinding during an exception).

    This approach prevents resource leaks caused by early function returns, thrown exceptions, or complex conditional logic where manual cleanup (like free(), fclose(), or unlock()) might be skipped.

  10. Compare C++ static and dynamic libraries

    C++ libraries are used for code reuse and modularization.

    Static Libraries (.a on Linux/macOS, .lib on Windows):

    • Mechanism: The linker extracts required code and data and copies it directly into the final executable.
    • Pros: Strong independence; the executable can run without external library files; lower overhead during function calls.
    • Cons: Larger executable size; updating the library requires recompiling and relinking all dependent programs.

    Dynamic Libraries (.so on Linux, .dylib on macOS, .dll on Windows):

    • Mechanism: The linker records references (names and signatures). The OS loads the library into memory at runtime, and multiple programs share a single instance.
    • Pros: Reduced disk and memory usage; libraries can be updated by replacing the file without recompiling the main program (provided interface compatibility is maintained).
    • Cons: Requires the library files to be present at runtime; slight performance overhead during initial loading/linking; potential for "missing .dll" errors.
  11. Understand C++ as a federation of four sub-languages

    To write efficient and reliable C++ code, it is critical to recognize that C++ is not a single monolithic language but a federation of four sub-languages. Each sub-language has its own rules, conventions, and best practices. Switching between these sub-languages requires a shift in programming strategy.

    The four sub-languages are:

    1. C: The foundation of C++. It includes core syntax (blocks, statements, preprocessor), built-in data types, pointers, and arrays. It follows a procedural programming paradigm and focuses on manual memory management and raw performance.
    2. Object-Oriented C++: Focuses on classes and objects. Key concepts include encapsulation, inheritance, polymorphism, constructors, and destructors. It follows the Object-Oriented Programming (OOP) paradigm, emphasizing design patterns and object lifecycle management.
    3. Template C++: The generic programming part of the language. It includes templates, template specialization, and template metaprogramming. This allows for type-independent code and can shift work from runtime to compile-time for higher efficiency.
    4. STL (Standard Template Library): A highly coordinated library built on templates. It consists of containers, iterators, algorithms, and function objects. It follows a paradigm based on the interaction between these components (e.g., using iterators to traverse containers rather than raw pointers).
  12. Understand C++ Scope and Lifetime

    In C++, Scope is a compile-time concept defining where an identifier can be accessed, while Lifetime is a runtime concept defining the duration from an object's creation to its destruction.

    Scope Types

    • Block Scope: Identifiers declared inside {} are visible from the declaration point to the closing }.
    • Function Scope: Labels (used with goto) are visible throughout the entire function body.
    • Global Scope: Identifiers declared outside all functions, classes, and blocks; visible from declaration to the end of the source file.
    • Class Scope: Members declared inside a class or struct. Accessed via objects (. or ->) or the scope resolution operator :: for static members.
    • Namespace Scope: Identifiers declared within a namespace, accessed via :: or using declarations.

    Lifetime (Storage Duration)

    • Automatic Storage: Local variables; created when entering the block and destroyed when leaving.
    • Static Storage: Global variables, static local variables, and static class members; created before main() and destroyed after main() or upon exit().
    • Dynamic Storage: Objects allocated via new or malloc on the heap; created at allocation and destroyed at delete.
    • Thread Storage: Variables marked with thread_local; lifetime is tied to the thread they were created in.