Skip to content

Instantly share code, notes, and snippets.

View dharanad's full-sized avatar
:octocat:
Available

Dharan Aditya dharanad

:octocat:
Available
View GitHub Profile
@dharanad
dharanad / cow_trie.rs
Last active July 26, 2024 14:06
A copy on write Trie
use std::collections::HashMap;
use std::hash::Hash;
use criterion::{black_box, Criterion, criterion_group, criterion_main};
#[derive(Clone)]
struct TrieNode<T: Clone> {
value: Option<T>,
children: HashMap<char, Box<TrieNode<T>>>,
}
package main
import (
"encoding/binary"
"errors"
"fmt"
"io"
"net"
"os"
"syscall"
@dharanad
dharanad / run.sh
Created July 22, 2022 12:25
Gojo Setup
#bin/sh
mkdir ProjectGojo
cd ProjectGojo || exit
git clone https://github.com/dharan1011/Gojo.git || exit
git clone https://github.com/dharan1011/GojoCdk.git || exit
cd GojoCdk || exit
cdk bootstrap
cdk deploy
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
@dharanad
dharanad / bs.md
Last active August 21, 2020 05:20
Binary Search Notes

Binary Search

computation of mid in binary search

the mid of range [low, high] where low and high define the search space, we apply binary search can be computed using formula

mid = low + high / 2

But this fails if sum of low and high exceeds 2^31-1. The resultant sum overflows to a negative value. This might result in unpredictable resutls or Index out of bound error.

Breakpoints : active regions
0 600 960 1280 1920 (in pixels)
xs sm md lg xl
value |0px 600px 960px 1280px 1920px
key |xs sm md lg xl
screen width |--------|--------|--------|--------|-------->
range | xs | sm | md | lg | xl
items : 0 1 2 3 4 5 6 7 8 9 10 11 12
@dharanad
dharanad / main.cpp
Last active November 16, 2022 08:36
C++ Competitive Programming Template
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for (i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (i = k; i >= n; --i)
#define r(type,x) type x; cin>>x;
#define w(x) r(int, x) while(x--)
@dharanad
dharanad / pbds.cpp
Created June 16, 2020 17:40
Policy Based Data Structures Usecases
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef
tree<
int,
@dharanad
dharanad / main.cpp
Last active June 16, 2020 10:08
C++ String Tokenising
#include <iostream>
#include <cstring>
using namespace std;
vector<string> split(string str,const char *delim){
// Convert from char * to char
char *cexp = new char[str.length() + 1]; // 1 extra char of null terminated character
strcpy(cexp, str.c_str());
// Tokenise character array
char *tok = strtok(cexp, delim);
@dharanad
dharanad / cpp-cp.code-snippets
Last active June 20, 2020 07:46
VSCode C++ Competitive Program Template Snippet
{
"cptemplate": {
// "scope": "",
"prefix": "cptemplate",
"body": [
"#include <bits/stdc++.h>",
"#include <ext/pb_ds/assoc_container.hpp>",
"#include <ext/pb_ds/tree_policy.hpp>",
"using namespace std;",
"using namespace __gnu_pbds;",