Skip to content

Instantly share code, notes, and snippets.

@graydon
graydon / move.rs
Created January 18, 2024 23:07
Ownership passing vs. borrowing
// This is just an elaboration of an off-hand toot I made earlier today
// concerning a coding pattern I find myself doing whenever possible: passing
// and returning owned values instead of borrowing references.
//
// I find it works well for long-lived values especially since the resulting
// composite objects have no lifetime qualifiers, so I don't have to plumb
// lifetimes through to all the code that uses them.
// Assumption: assume we have a few objects like this: a network connection, a
// database, some commands, etc. and we want to make a session type that uses
@jxe
jxe / Chatterbase.carbide.md
Last active August 3, 2018 00:41
Chatterbase

Chatterbase

@lukego
lukego / gist:4706097
Last active December 12, 2015 03:19
Table data structure that "garbage collects" not-recently-used items in O(1) time

I use this data structure all the time. Can someone leave a comment and tell me what it's called?

  1. insert(k,v): add a new value
  2. lookup(k): lookup an existing value
  3. age(): delete old entries (that have not been used since previous call to age())
# Initialize 'old' and 'new' to empty tables
local old, new = {}, {}