SIngle Thread LRUCache in C++

#include <iostream> #include <list> #include <unordered_map> using namespace std; size_t capacity; class LRUCache { public: bool Lookup(int key, int *price) { auto it = hash_table.find(key); if (it == hash_table.end()) { return false; } *price = it->second.second; // update the key in the queue MoveToFront(key, it); return true; } […]

Understanding Ruby Symbols

Ruby is an interpreted language. It is dynamically typed and uses a new memory for a variable. A variable has a name and a value. Symbols are an optimized variable that holds single instance of memory. It is good for variables that assume the same values across the […]

How a Regex Engine Work?

A regular expression defines a set of string. A regex engine matches a pattern against input and returns true/false for the condition that pattern exists in the input. I have got a C++ implementation of a regex engine which uses simple constructs of matching the following: A single […]

How to Write Clean Code?

Basic Hygiene Leave the place cleaner than you got it. Naming Convention Do one thing in a function. Name should reflect the action. Function name is a verb. Declare literals ([a-z]+, [0-9]+) as constants. Functions The function should not exceed twenty lines. Each if, else, while statement can […]