Skip to content

Instantly share code, notes, and snippets.

@vmolsa
vmolsa / ill.rs
Last active August 8, 2025 08:34
Indexed Linked List
//! # Index-based doubly-linked list + cursor + task queue
//!
//! This module implements a **doubly-linked list backed by indexable storage**
//! (arenas, slabs, or fixed arrays) rather than raw pointers. It includes:
//!
//! - [`NodeStorage`] — abstraction over the backing store (keys are indices/handles).
//! - [`ILL`] — the index-linked list itself (head/tail + per-node `prev`/`next`).
//! - [`IndexLinkedList`] — trait exposing a cursor and basic push/iterate ops.
//! - [`NodeCursor`] / [`CursorMut`] — **mutable, bidirectional cursor** with a
//! *gap* (`prev`, `current`, `next`) for true **insert-before/after** and removals.
@vmolsa
vmolsa / cachelist.rs
Last active September 14, 2024 08:29
Linked list with cache option
use std::{fmt::{self, Debug},ops::{Deref, DerefMut}, ptr::NonNull};
/// A doubly linked list that caches nodes for reuse to minimize allocation overhead.
///
/// `CacheList` is designed for scenarios where frequent insertions and deletions occur,
/// and reusing nodes can significantly improve performance by reducing memory allocations.
///
/// # Type Parameters
///
/// - `T`: The type of values stored in the list.
@vmolsa
vmolsa / batch.rs
Last active October 10, 2024 03:05
Stack allocated futures as Batch
use std::{future::Future, pin::Pin, task::{Context, Poll}};
/// A structure representing a batch of futures that can be polled concurrently.
///
/// # Type Parameters
///
/// * `'a` - The lifetime of the futures.
/// * `T` - The output type of the futures on successful completion.
/// * `E` - The error type of the futures on failure.
/// * `F` - The type of the futures being batched.
@vmolsa
vmolsa / um.rs
Created July 14, 2024 13:36
Unified Mutex
// LICENSE: Apache-2.0
use std::{
future::poll_fn,
task::{Context, Poll},
ops::{Deref, DerefMut},
};
#[cfg(not(feature = "no_mutex"))]
use std::{
@vmolsa
vmolsa / hexdump.zig
Last active January 19, 2023 00:18
Hexdump written in zig
// Exmaple: try hexdump(std.io.getStdOut().writer(), "Hello World", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
//
// Hello World
//
// 0000: 4C 6F 72 65 6D 20 69 70 73 75 6D 20 64 6F 6C 6F Lorem ipsum dolo
// 0016: 72 20 73 69 74 20 61 6D 65 74 2C 20 63 6F 6E 73 r sit amet, cons
// 0032: 65 63 74 65 74 75 72 20 61 64 69 70 69 73 63 69 ectetur adipisci
// 0048: 6E 67 20 65 6C 69 74 2C 20 73 65 64 20 64 6F 20 ng elit, sed do
// 0064: 65 69 75 73 6D 6F 64 20 74 65 6D 70 6F 72 20 69 eiusmod tempor i
// 0080: 6E 63 69 64 69 64 75 6E 74 20
@vmolsa
vmolsa / functor.h
Created November 15, 2016 04:27
C++ Functor
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 vmolsa <ville.molsa@gmail.com> (http://github.com/vmolsa)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@vmolsa
vmolsa / rtc-ping-pong.js
Created March 23, 2015 20:58
node-webrtc test for sending buffers
var rtc = require('rtc-stream');
function runTest(instances, channels, times, size, callback) {
var result = {
instances: 0,
channels: 0,
bytesReceived: 0,
bytesSended: 0,
};
@vmolsa
vmolsa / Makefile
Last active August 29, 2015 14:08
Queue / Array in C++
all:
g++ -o QueueArrayTest test.cc -lpthread --debug