summaryrefslogtreecommitdiff
path: root/src/gen_lib/vector.lem
blob: e7b20aeb32fdda60d9926d55c23d7e074d187a3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
open import Pervasives

type bit = Zero | One | Undef
type vector = Vector of list bit * nat

let read_vector_subrange is_inc (Vector bs start) n m =
  let (length,offset) = if is_inc then (m-n+1,n-start) else (n-m+1,start-n) in
  let (_,suffix) = List.splitAt offset bs in
  let (subvector,_) = List.splitAt length suffix in
  Vector subvector n

let write_vector_subrange is_inc (Vector bs start) n m (Vector bs' _) =
  let (length,offset) = if is_inc then (m-n+1,n-start) else (n-m+1,start-n) in
  let (prefix,_) = List.splitAt offset bs in
  let (_,suffix) = List.splitAt (offset + length) bs in
  Vector (prefix ++ (List.take length bs') ++ suffix) start