Skip to content

Instantly share code, notes, and snippets.

View cheremin's full-sized avatar

Ruslan cheremin

View GitHub Profile
@cheremin
cheremin / PaginationWastedSizeSimulation.java
Created January 18, 2023 10:03
Simulation: space wasted due to records being page-aligned
import java.util.ArrayList;
import java.util.OptionalDouble;
import java.util.concurrent.ThreadLocalRandom;
class PaginationWastedSizeSimulation {
public static void main(final String[] args) {
//Records of random size, with avg=averageRecordSize
//Page of pageSize
//If record doesn't fit page -- it is moved to the next page, remaining space on the first page
class Solution {
private static final char OP_CONCATENATE = ' ';
/**
* Operators, ordered by priority
*/
private static final char[] OPERATORS = { OP_CONCATENATE, '*', '+', '-' };
private static final boolean DEBUG = false;
@cheremin
cheremin / MysteriousServerTest.java
Last active May 23, 2019 16:18
Waiting time non-monotonicity example (waiting time paradox in queueing systems with vacations) https://dev.cheremin.info/2019/05/waiting-time-paradox-3.html
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ThreadLocalRandom;
import org.junit.Ignore;
import org.junit.Test;
/** time is always in milliseconds */
public class MysteriousServerTest {
private static final ThreadLocalRandom RND = ThreadLocalRandom.current();
@cheremin
cheremin / Vector2D
Last active February 22, 2016 18:00
public static final class Vector2D {
private double x;
private double y;
public Vector2D( final double x,
final double y ) {
this.x = x;
this.y = y;
}