package granary

  1. Overview
  2. Docs
Pure-OCaml SQL engine

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.0.3.tar.gz
sha256=8b18780ea373be48301d9f333925860a2f9110fc0ac28684295118d72b65a67e
sha512=25ca3c9c5e2b528704a542502e0f37dc33ba003f65622d969b8c2b800778585f8ef0cf89b36e6679832e3993e8303aecddfc662742baf7044d6afe4a796b8f11

doc/src/granary.encoding/rowid.ml.html

Source file rowid.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let encode n =
  let n = Int64.logxor n 0x8000_0000_0000_0000L in
  let b = Bytes.create 8 in
  for i = 0 to 7 do
    let byte = Int64.to_int (Int64.shift_right_logical n ((7 - i) * 8)) land 0xFF in
    Bytes.set_uint8 b i byte
  done;
  b
;;

let decode b =
  let n = ref 0L in
  for i = 0 to 7 do
    let byte = Bytes.get_uint8 b i in
    n := Int64.logor !n (Int64.shift_left (Int64.of_int byte) ((7 - i) * 8))
  done;
  Int64.logxor !n 0x8000_0000_0000_0000L
;;

[@@@ai_disclosure "ai-generated"]
[@@@ai_model "claude-opus-4-7"]
[@@@ai_provider "Anthropic"]