diskann-quantization 0.51.0

DiskANN is a fast approximate nearest neighbor search library for high dimensional data
Documentation
/*
 * Copyright (c) Microsoft Corporation.
 * Licensed under the MIT license.
 */

// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
extern crate flatbuffers;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::mem;
use core::cmp::Ordering;
use self::flatbuffers::{EndianScalar, Follow};
use super::*;
pub enum QuantizerOffset {}
#[derive(Copy, Clone, PartialEq)]

pub struct Quantizer<'a> {
  pub _tab: flatbuffers::Table<'a>,
}

impl<'a> flatbuffers::Follow<'a> for Quantizer<'a> {
  type Inner = Quantizer<'a>;
  #[inline]
  unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
    Self { _tab: flatbuffers::Table::new(buf, loc) }
  }
}

impl<'a> Quantizer<'a> {
  pub const VT_QUANTIZER: flatbuffers::VOffsetT = 4;
  pub const VT_NBITS: flatbuffers::VOffsetT = 6;

  #[inline]
  pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
    Quantizer { _tab: table }
  }
  #[allow(unused_mut)]
  pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
    _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
    args: &'args QuantizerArgs<'args>
  ) -> flatbuffers::WIPOffset<Quantizer<'bldr>> {
    let mut builder = QuantizerBuilder::new(_fbb);
    builder.add_nbits(args.nbits);
    if let Some(x) = args.quantizer { builder.add_quantizer(x); }
    builder.finish()
  }


  #[inline]
  pub fn quantizer(&self) -> SphericalQuantizer<'a> {
    // Safety:
    // Created from valid Table for this object
    // which contains a valid value in this slot
    unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<SphericalQuantizer>>(Quantizer::VT_QUANTIZER, None).unwrap()}
  }
  #[inline]
  pub fn nbits(&self) -> u32 {
    // Safety:
    // Created from valid Table for this object
    // which contains a valid value in this slot
    unsafe { self._tab.get::<u32>(Quantizer::VT_NBITS, Some(0)).unwrap()}
  }
}

impl flatbuffers::Verifiable for Quantizer<'_> {
  #[inline]
  fn run_verifier(
    v: &mut flatbuffers::Verifier, pos: usize
  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
    use self::flatbuffers::Verifiable;
    v.visit_table(pos)?
     .visit_field::<flatbuffers::ForwardsUOffset<SphericalQuantizer>>("quantizer", Self::VT_QUANTIZER, true)?
     .visit_field::<u32>("nbits", Self::VT_NBITS, false)?
     .finish();
    Ok(())
  }
}
pub struct QuantizerArgs<'a> {
    pub quantizer: Option<flatbuffers::WIPOffset<SphericalQuantizer<'a>>>,
    pub nbits: u32,
}
impl<'a> Default for QuantizerArgs<'a> {
  #[inline]
  fn default() -> Self {
    QuantizerArgs {
      quantizer: None, // required field
      nbits: 0,
    }
  }
}

pub struct QuantizerBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> QuantizerBuilder<'a, 'b, A> {
  #[inline]
  pub fn add_quantizer(&mut self, quantizer: flatbuffers::WIPOffset<SphericalQuantizer<'b >>) {
    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<SphericalQuantizer>>(Quantizer::VT_QUANTIZER, quantizer);
  }
  #[inline]
  pub fn add_nbits(&mut self, nbits: u32) {
    self.fbb_.push_slot::<u32>(Quantizer::VT_NBITS, nbits, 0);
  }
  #[inline]
  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> QuantizerBuilder<'a, 'b, A> {
    let start = _fbb.start_table();
    QuantizerBuilder {
      fbb_: _fbb,
      start_: start,
    }
  }
  #[inline]
  pub fn finish(self) -> flatbuffers::WIPOffset<Quantizer<'a>> {
    let o = self.fbb_.end_table(self.start_);
    self.fbb_.required(o, Quantizer::VT_QUANTIZER,"quantizer");
    flatbuffers::WIPOffset::new(o.value())
  }
}

impl core::fmt::Debug for Quantizer<'_> {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    let mut ds = f.debug_struct("Quantizer");
      ds.field("quantizer", &self.quantizer());
      ds.field("nbits", &self.nbits());
      ds.finish()
  }
}
#[inline]
/// Verifies that a buffer of bytes contains a `Quantizer`
/// and returns it.
/// Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `root_as_quantizer_unchecked`.
pub fn root_as_quantizer(buf: &[u8]) -> Result<Quantizer, flatbuffers::InvalidFlatbuffer> {
  flatbuffers::root::<Quantizer>(buf)
}
#[inline]
/// Verifies that a buffer of bytes contains a size prefixed
/// `Quantizer` and returns it.
/// Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `size_prefixed_root_as_quantizer_unchecked`.
pub fn size_prefixed_root_as_quantizer(buf: &[u8]) -> Result<Quantizer, flatbuffers::InvalidFlatbuffer> {
  flatbuffers::size_prefixed_root::<Quantizer>(buf)
}
#[inline]
/// Verifies, with the given options, that a buffer of bytes
/// contains a `Quantizer` and returns it.
/// Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `root_as_quantizer_unchecked`.
pub fn root_as_quantizer_with_opts<'b, 'o>(
  opts: &'o flatbuffers::VerifierOptions,
  buf: &'b [u8],
) -> Result<Quantizer<'b>, flatbuffers::InvalidFlatbuffer> {
  flatbuffers::root_with_opts::<Quantizer<'b>>(opts, buf)
}
#[inline]
/// Verifies, with the given verifier options, that a buffer of
/// bytes contains a size prefixed `Quantizer` and returns
/// it. Note that verification is still experimental and may not
/// catch every error, or be maximally performant. For the
/// previous, unchecked, behavior use
/// `root_as_quantizer_unchecked`.
pub fn size_prefixed_root_as_quantizer_with_opts<'b, 'o>(
  opts: &'o flatbuffers::VerifierOptions,
  buf: &'b [u8],
) -> Result<Quantizer<'b>, flatbuffers::InvalidFlatbuffer> {
  flatbuffers::size_prefixed_root_with_opts::<Quantizer<'b>>(opts, buf)
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a Quantizer and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid `Quantizer`.
pub unsafe fn root_as_quantizer_unchecked(buf: &[u8]) -> Quantizer {
  flatbuffers::root_unchecked::<Quantizer>(buf)
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a size prefixed Quantizer and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid size prefixed `Quantizer`.
pub unsafe fn size_prefixed_root_as_quantizer_unchecked(buf: &[u8]) -> Quantizer {
  flatbuffers::size_prefixed_root_unchecked::<Quantizer>(buf)
}
pub const QUANTIZER_IDENTIFIER: &str = "sq00";

#[inline]
pub fn quantizer_buffer_has_identifier(buf: &[u8]) -> bool {
  flatbuffers::buffer_has_identifier(buf, QUANTIZER_IDENTIFIER, false)
}

#[inline]
pub fn quantizer_size_prefixed_buffer_has_identifier(buf: &[u8]) -> bool {
  flatbuffers::buffer_has_identifier(buf, QUANTIZER_IDENTIFIER, true)
}

#[inline]
pub fn finish_quantizer_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
    fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
    root: flatbuffers::WIPOffset<Quantizer<'a>>) {
  fbb.finish(root, Some(QUANTIZER_IDENTIFIER));
}

#[inline]
pub fn finish_size_prefixed_quantizer_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset<Quantizer<'a>>) {
  fbb.finish_size_prefixed(root, Some(QUANTIZER_IDENTIFIER));
}