Results for “Small algorithms & bit operations”
Small, practical examples. Search by task or narrow things down below.
Build a mutable generic list
PowerShell: A generic list supports repeated additions without copying an entire array each time.
PowerShell✓ Tested
Calculate a file’s SHA-256 digest
PowerShell: Get-FileHash hashes bytes without requiring the caller to load the whole file.
PowerShell✓ Tested
Calculate a lexical relative path
C++: lexically_relative compares path components without requiring the paths to exist.
C++✓ Tested
Calculate changes between successive readings
C++: adjacent_difference keeps the first value and then writes each difference from its predecessor.
C++✓ Tested
Calculate cumulative totals
C++: partial_sum writes the sum of each input prefix to the output sequence.
C++✓ Tested
Calculate the dot product of two vectors
C++: inner_product multiplies corresponding elements and accumulates them from a chosen seed.
C++✓ Tested
Check exact array membership
Bash Scripts: Compare each element literally instead of searching a concatenated string.
Bash Scripts✓ Tested
Check whether a range is already sorted
C++: is_sorted reports ordering without modifying the input.
C++✓ Tested
Clean up a temporary directory automatically
Python: Use TemporaryDirectory as a context manager so cleanup also happens after exceptions.
Python✓ Tested
Combine results while retaining duplicates
SQL: UNION ALL does not spend work removing equal rows.
SQL✓ Tested
Combine results while retaining duplicates
SQL Server: UNION ALL does not spend work removing equal rows.
SQL Server✓ Tested
Combine results while retaining duplicates
Postgres: UNION ALL does not spend work removing equal rows.
Postgres✓ Tested