package p4spectec

  1. Overview
  2. Docs
P4-SpecTec: A mechanization toolchain for the P4 Programming Language

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.2.tar.gz
md5=1a3bc0a385fe1ecf403c019f49aa6de6
sha512=5d20b5821f33e2a3a5419b208606f27c01511994c2b3b1e1cdf4c077056dfd0aa81682af0720e1060ee2bfb0341918fcc4c53159820205a2bc32b725e5c1a714

doc/src/p4spectec.util/deque.ml.html

Source file deque.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(* Deque implementation with a single list *)

type 'a t = 'a list [@@deriving yojson]

let empty = []
let is_empty = List.is_empty
let push_back (x : 'a) (q : 'a t) : 'a t = q @ [ x ]
let push_front : 'a -> 'a t -> 'a t = List.cons

let pop_back_opt (q : 'a t) =
  match List.rev q with hd :: tl -> Some (hd, List.rev tl) | [] -> None

let pop_back (q : 'a t) = q |> pop_back_opt |> Option.get

let pop_front_opt (q : 'a t) =
  match q with hd :: tl -> Some (hd, tl) | [] -> None

let pop_front (q : 'a t) = q |> pop_front_opt |> Option.get