Module Ocsigen_cache.Dlist


module Dlist: sig .. end
Doubly-linked lists with maximum size.

type 'a t 
type 'a node 
val create : int -> 'a t
val add : 'a -> 'a t -> 'a option
Adds an element to the list, and possibly returns the element that has been removed if the maximum size was exceeded.
val remove : 'a node -> unit
Removes an element from its list. If it is not in a list, it does nothing. If it is in a list, it calls the finaliser, then removes the element. If the finaliser fails with an exception, the element is removed and the exception is raised again.
val up : 'a node -> unit
Removes the element from its list without finalising, then adds it as newest.
val newest : 'a t -> 'a node option
val oldest : 'a t -> 'a node option
val size : 'a t -> int
val maxsize : 'a t -> int
val value : 'a node -> 'a
val list_of : 'a node -> 'a t option
The list to which the node belongs
val remove_n_oldest : 'a t -> int -> 'a list
remove the n oldest values (or less if the list is not long enough) ; returns the list of removed values
val move : 'a node -> 'a t -> 'a option
Move a node from one dlist to another one, without finalizing. If one value is removed from the destination list (because its maximum size is reached), it is returned (after finalisation).
val set_maxsize : 'a t -> int -> 'a list
change the maximum size ; returns the list of removed values, if any.
val set_finaliser : ('a node -> unit) -> 'a t -> unit
set a function to be called automatically on a piece of data just before it disappears from the list (either by explicit removal or because the maximum size is exceeded)
val get_finaliser : 'a t -> 'a node -> unit