Skip to content

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Competitive Programming Snippets

A personal library of C++ algorithms, data structures, and mathematical routines for competitive programming, organized so it can be converted into ready-to-use code snippets for VSCode and Sublime Text.

What's in here

The Code/ directory contains 106 C++ source files (plus a small debugger header and a text reference note) grouped into topic folders:

  • DATA STRUCTURE: Bitset, Cartesian Tree, Convex Hull Trick, Cumulative Table, Disjoint Set Union, Dynamic Set, Explicit Treap, Hash Table, Heavy Light Decomposition, Li Chao Tree, Link Cut Tree, Lowest Common Ancestor, Monotonic Queue/Stack, Order Statistic Set, Rollback Trick, Segment Tree, Slope Trick, Sparse Table, Sqrt Decomposition (including Mo's Algorithm), Venice Technique
  • DYNAMIC PROGRAMMING: Divide and Conquer Optimization
  • GAME THEORY: Grundy numbers and related game analysis snippets
  • GRAPH THEORY: Centroid Decomposition, Euler Tour, Flow Theory, Graph Structure, Inverse Graph Components
  • MATHEMATICS: Algebra, Combinatorial Theory, Number Theory, Numerical Math
  • MISCELLANY: Big Number, Calendar, Coordinate Compression, Debugger, IOS_BASE, Longest Increasing Subsequence, Modular Number, Pragma, Random, Stress testing, and a base Template
  • STRING: Aho-Corasick, Hashing, Manacher, Suffix Array

Each .cpp file in Code/ begins with a // TAB_TRIGGER "NAME" comment, which names the snippet trigger keyword used when it's converted into an editor snippet.

Tech stack

  • C++ (the snippet bodies themselves, targeting competitive programming judges)
  • Python 3 (generateSnippets.py), used only to build the editor snippet files from the C++ sources

How snippet generation works

generateSnippets.py performs a two-stage build:

  1. generate_sublime_snippets(): copies Code/ into a new Sublime-snippets/ directory, reads the TAB_TRIGGER comment out of each .cpp file, wraps the remaining code in a <snippet> XML block, and writes it out as a .sublime-snippet file (replacing the original .cpp).
  2. generate_vscode_snippets(): copies Sublime-snippets/ into VSCode-snippets/, parses each .sublime-snippet file's code and trigger, and rewrites it as a VSCode .code-snippets JSON file (with scope: "cpp", a prefix, body, and description).

Both generated folders (Sublime-snippets/, VSCode-snippets/) are rebuilt from scratch (deleted and recreated) each time the script runs.

Usage

Generate the VSCode and Sublime Text snippet files from the source in Code/:

python3 generateSnippets.py

This produces:

  • Sublime-snippets/ : one .sublime-snippet file per source file, mirroring the Code/ folder structure
  • VSCode-snippets/ : one .code-snippets file per source file, generated from the Sublime snippets

Import either folder into the corresponding editor to get the algorithms available as typed snippets (using each file's TAB_TRIGGER as the trigger prefix).

Notes

This is a personal reference collection built up over time rather than a general-purpose package; there is no build system, test suite, or dependency manifest beyond the Python standard library used by generateSnippets.py.

About

A collection of personal C++ competitive programming algorithms covering data structures, graph theory, string processing, mathematics, etc. Includes a Python script to generate VSCode and Sublime Text snippets.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages