12345678910111213141516171819202122232425262728293031(* Claude Code
*
* Copyright (C) 2026 Yoann Padioleau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* (LGPL) as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*)(* See Interpolation.mli *)type'at={delay:float;mutablesnapshots:(float*'a)list(* the oldest first *)}letcreate~(delay:float):'at={delay;snapshots=[]}(* kept: the ones not older than a second before the newest *)letadd(t:'at)~(time:float)(x:'a):unit=t.snapshots<-List.filter(fun(at,_)->at>=time-.1.)(t.snapshots@[(time,x)])letsample(t:'at)~(now:float):('a*'a*float)option=letat=now-.t.delayinletrecaround=function|[]->None|[(_,x)]->Some(x,x,0.)|(t0,x0)::((t1,x1)::_asrest)->ifat<t0thenSome(x0,x0,0.)elseifat<=t1thenSome(x0,x1,ift1>t0then(at-.t0)/.(t1-.t0)else0.)elsearoundrestinaroundt.snapshots