9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-23 03:53:29 +01:00
qp2/ocaml/MO_class.ml

66 lines
1.7 KiB
OCaml
Raw Normal View History

2019-01-25 11:39:31 +01:00
open Qptypes
2020-05-25 11:31:28 +02:00
open Qputils
2019-03-13 10:42:18 +01:00
open Sexplib.Std
2019-01-25 11:39:31 +01:00
type t =
| Core of MO_number.t list
| Inactive of MO_number.t list
| Active of MO_number.t list
| Virtual of MO_number.t list
| Deleted of MO_number.t list
[@@deriving sexp]
let to_string x =
let print_list l =
2020-05-25 11:31:28 +02:00
let s = list_map (fun x-> MO_number.to_int x |> string_of_int ) l
2019-03-13 10:42:18 +01:00
|> (String.concat ", ")
2019-01-25 11:39:31 +01:00
in
"("^s^")"
in
match x with
| Core [] -> "Core"
| Inactive [] -> "Inactive"
| Active [] -> "Active"
| Virtual [] -> "Virtual"
| Deleted [] -> "Deleted"
| Core l -> "Core : "^(print_list l)
| Inactive l -> "Inactive : "^(print_list l)
| Active l -> "Active : "^(print_list l)
| Virtual l -> "Virtual : "^(print_list l)
| Deleted l -> "Deleted : "^(print_list l)
let of_string s =
2019-03-13 11:35:21 +01:00
match (String.lowercase_ascii s) with
2019-01-25 11:39:31 +01:00
| "core" -> Core []
| "inactive" -> Inactive []
| "active" -> Active []
| "virtual" -> Virtual []
| "deleted" -> Deleted []
| _ -> failwith "MO_class should be (Core|Inactive|Active|Virtual|Deleted)"
let _mo_number_list_of_range range =
2020-05-25 11:31:28 +02:00
Range.of_string range |> list_map MO_number.of_int
2019-01-25 11:39:31 +01:00
let create_core range = Core (_mo_number_list_of_range range)
let create_inactive range = Inactive (_mo_number_list_of_range range)
let create_active range = Active (_mo_number_list_of_range range)
let create_virtual range = Virtual (_mo_number_list_of_range range)
let create_deleted range = Deleted (_mo_number_list_of_range range)
let to_bitlist n_int x =
match x with
| Core l
| Inactive l
| Active l
| Virtual l
| Deleted l -> Bitlist.of_mo_number_list n_int l