Posts

VECPP.c

#include <tape_t.h> #include <string_t.h> #include <tuple_t.h> #include <bool_t.h> /**** first design #include, #define VAR, #define FUNC() and #ifdef, #elif and #endif *****/ enum MacroType {     define_t,     include_t,     line_t,     undef_t,     error_tt,     pragma_t,     defined_t,     if_t,     ifdef_t,     ifndef_t,     elif_t,     else_t,     endif_t,     COMPILER_DATA,     UNDEFINED,     MAX_TYPE }; MacroType getIndexFromStr(string_t s) {     string_t tmp;     char* arr[13] = { "define","include","line","undef","error","pragma","defined","if","ifdef","ifndef","elif","else","endif" };     for(int i=0; i< 13; i++)     {         tmp = string(arr[i]);         if((compare(tmp,s)) == 0)         ...

Comparision with Quick Sort

 #include <iostream> #include <vector> #include <map> #include <climits> #include <chrono>  // Added for timing using namespace std; using namespace std::chrono;  // Added for chrono #define MAP_SIZE USHRT_MAX #define OFFSET MAP_SIZE/2 void Map_sort(vector<int> &nums) {     vector<int> temp;     int arr[MAP_SIZE] = {0};     int maxElement = SHRT_MIN;     int minElement = SHRT_MAX;          for(int i=0; i<nums.size(); i++) {         if(nums[i] > maxElement) maxElement = nums[i];         if(nums[i] < minElement) minElement = nums[i];         arr[nums[i]+OFFSET]++;     }          int j=0;     for(int i=minElement; i<= maxElement; i++) {         if(arr[i+OFFSET] >= 1) {              for(int coun...

Map sort 5 with stack array and negative 16 bit numbers

#include <iostream> #include <vector> #include <map> #include <climits> using namespace std; #define MAP_SIZE USHRT_MAX #define OFFSET MAP_SIZE/2 void Map_sort(vector<int> &nums) {     vector<int> temp;     int arr[MAP_SIZE];     int maxElement = SHRT_MIN;     int minElement = SHRT_MAX;     for(int i=0; i<nums.size(); i++)     {         if(maxElement < nums[i])         {             maxElement = nums[i];         }         if(minElement > nums[i])         {             minElement = nums[i];         }         arr[nums[i]+OFFSET]++;              }     int j=0;     for(int i=minElement; i<= maxElement; i++ )     {  ...

Map sort 4 with array version

#include <iostream> #include <vector> #include <map> #include <climits> using namespace std; void Map_sort(vector<int> &nums) {     vector<int> temp;     int arr[20000];     int maxElement = INT_MIN;     int minElement = INT_MAX;     for(int i=0; i<nums.size(); i++)     {         if(maxElement < nums[i])         {             maxElement = nums[i];         }         if(minElement > nums[i])         {             minElement = nums[i];         }         arr[nums[i]]++;              }     int j=0;     for(int i=minElement; i<= maxElement; i++ )     {         if (arr[i] >= 1) {      ...

Map sort 3 with duplicates

#include <iostream> #include <vector> #include <map> #include <climits> using namespace std; void Map_sort(vector<int> &nums) {     vector<int> temp;     std::map<int,int> mp;     int maxElement = INT_MIN;     int minElement = INT_MAX;     for(int i=0; i<nums.size(); i++)     {         if(maxElement < nums[i])         {             maxElement = nums[i];         }         if(minElement > nums[i])         {             minElement = nums[i];         }         mp[nums[i]]++;              }     int j=0;     for(int i=minElement; i<= maxElement; i++ )     {         if (mp[i] >= 1) {  ...

Map sort 2

/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <iostream> #include <vector> #include <map> #include <climits> using namespace std; void map_sort(vector<int> &nums) {     vector<int> temp;     std::map<int,bool> mp;     int maxElement = INT_MIN;     int minElement = INT_MAX;     for(int i=0; i<nums.size(); i++)     {         if(maxElement < nums[i])         {             maxElement = nums[i];       ...

Map sort

/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <iostream> #include <vector> #include <map> #include <climits> using namespace std; vector<int> map_sort(vector<int> &nums) {     vector<int> temp;     std::map<int,bool> mp;     int maxElement = INT_MIN;     int minElement = INT_MAX;     for(int i=0; i<nums.size(); i++)     {         if(maxElement < nums[i])         {             maxElement = nums[i];   ...

Optimization of threads

 threadpool co-routines load balancing

UI Library

 small ui library and easy to use is:- microui https://github.com/rxi/microui

Microservices study material

 https://microservices.io/index.html https://www.researchgate.net/post/How_to_create_a_simple_microservice_from_C https://members.tsdsi.in/s/H2tdMnN6EHeMgFw

C++ Specification

 https://timsong-cpp.github.io/cppwp/n4659/

Overloading same function signature

  # include <iostream> template < typename T> void foo (T...) { std :: cout << 'A' ;} template < typename ... T> void foo (T...) { std :: cout << 'B' ;} int main () { foo( 1 ); foo( 1 , 2 ); }

Competitive coding

#include <iostream> #include <map> #include <vector> #include <filesystem> #include <fstream> #include <string> using namespace std; namespace fs = std::filesystem; std::string readFile(fs::path path) {     // Open the stream to 'lock' the file.     std::ifstream f(path, std::ios::in | std::ios::binary);     // Obtain the size of the file.     const auto sz = fs::file_size(path);     // Create a buffer.     std::string result(sz, '\0');     // Read the whole file into the buffer.     f.read(result.data(), sz);     return result; } int main() {      string line_str;      fs::path p = "extents.txt";        string result = readFile(p);      stringstream X(result);      std::multimap<long long,long long> m;      int i=0;      while(getline(X,line_s...

std::regex

 #include <regex> if(std::regex_match(uriPath, std::regex( "blogger.com/blog/post/[A-Za-z0-9]{32}"))) {

Design Patterns worked in My career

 Factory Handler DAO Acceptor-Connector Reactor Singleton

Optimization of C++ using Libraries and Design Patterns

 ETL(Embedded Template Library) Threadpool pattern (Optimization of thread based system) Object pool pattern (for configuration reading) string pool memory pool Fast Lane pattern (for file or db reading) singleton pattern std::async valarray std::span Serialization(Protobuffer/Kafka)

Principles in C++

  One Definition Rule Rule of three Tagged Constructors    Small object optimization( https://riptutorial.com/cplusplus/example/31654/small-object-optimization) Empty Base Class Optimization Optimizing by executing less code Expression templates Fold Expressions Perfect forwarding Returning several values continuation passing style Function Object Consumer Returning several values from a function Argument Dependent Name Lookup A moved-from optional Constexpr unions Deferred argument evaluation Preconditions Empty list initialization Intuitive interface The inline keyword as ODR guard dismisser noexcept destructors Value-initialization with C++ Too perfect forwarding variadic macros Ref-qualifiers Inadvertent conversions conditional copy constructor String’s interface Efficient optional values Overload resolution Sessions and object lifetimes Competing constructors Toggles in functions Compile-time string concatenation A friendly type predicate Requires-expressio...

C++ Idioms

 http://cplusplus.bordoon.com/cplusplusadvice.html https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Print_Version RTTI Virtual functions shared_ptr etc Templates Virtual inheriting Variadic macros Also useful: Attributes (it depends on your compiler) Variadic templates Variadic functions Constexpr (sorting in compile time / calculating hash of strings etc... but the latter is related to the last section) Lambdas Useful for brainfucking or in special cases: CRTP SFINAE inable_if (type traits) Foreach macro User-defined literals opaque pointer https://akrzemi1.wordpress.com/page/2/ https://www.ritambhara.in/category/cpp/