### Build Example Open Hypergraph with `lax` Interface Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/index.html Demonstrates how to construct an example open hypergraph using the mutable, imperative `lax` interface. This involves creating nodes and edges, and setting their sources and targets. ```rust use open_hypergraphs::lax::* pub enum NodeLabel { I8 }; pub enum EdgeLabel { Sub, Neg }; fn build() -> OpenHypergraph { use NodeLabel::*; use EdgeLabel::*; // Create an empty OpenHypergraph. let mut example = OpenHypergraph::::empty(); // Create all 4 nodes let x = example.new_node(I8); let a = example.new_node(I8); let y = example.new_node(I8); let z = example.new_node(I8); // Add the "Sub" hyperedge with source nodes `[x, y]` and targets `[a]` example.new_edge(Sub, Hyperedge { sources: vec![x, y], targets: vec![a] }); // Add the 'Neg' hyperedge with sources `[a]` and targets `[z]` example.new_edge(Neg, Hyperedge { sources: vec![a], targets: vec![z] }); // set the sources and targets of the example example.sources = vec![x, y]; example.targets = vec![x, z]; // return the example example } let f = build(); assert_eq!(f.sources.len(), 2); assert_eq!(f.targets.len(), 2); ``` -------------------------------- ### starts_with Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Checks if the slice starts with the provided needle. ```APIDOC ## starts_with ### Description Returns true if `needle` is a prefix of the slice or equal to the slice. ### Parameters - **needle** (&[T]) - Required - The prefix to check for. ### Response - **bool** - True if the slice starts with the needle. ``` -------------------------------- ### Check slice prefix with starts_with Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Verifies if a slice starts with a specific sequence. ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ```rust let v = &[10, 40, 30]; assert!(v.starts_with(&[])); let v: &[u8] = &[]; assert!(v.starts_with(&[])); ``` -------------------------------- ### Generate Indices from Start to Stop Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/traits/trait.NaturalArray.html Creates an array of indices starting from `start` up to (but not including) `stop`. If `start` equals `stop`, an empty array is returned. ```rust use open_hypergraphs::array::{*, vec::*}; let x0 = VecArray::arange(&0, &3); assert_eq!(x0, VecArray(vec![0, 1, 2])); let x1 = VecArray::arange(&0, &0); assert_eq!(x1, VecArray(vec![])); ``` -------------------------------- ### FiniteFunction Cumulative Sum Example 1 Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/vec/type.FiniteFunction.html Demonstrates the cumulative sum calculation for a non-empty finite function. ```rust let f = FiniteFunction::::new(VecArray(vec![3, 0, 1, 4]), 5).unwrap(); let c = f.cumulative_sum(); assert_eq!(c.table, VecArray(vec![0, 3, 3, 4])); assert_eq!(c.target(), 8); ``` -------------------------------- ### Example: FiniteFunction::constant Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/finite_function/arrow/struct.FiniteFunction.html Demonstrates the construction of a constant finite function and verifies its equality with a composed function and its expected value. ```rust let (x, a, b) = (2, 3, 2); let actual = FiniteFunction::::constant(a, x, b); let expected = FiniteFunction::new(VecArray(vec![2, 2, 2]), x + b + 1).unwrap(); assert_eq!(actual, expected); // Check equal to `!_a ; ι₁ ; ι₀` let i1 = FiniteFunction::::inj1(x, 1); let i0 = FiniteFunction::inj0(x + 1, b); let f = FiniteFunction::terminal(a); let h = f.compose(&i1).expect("b").compose(&i0).expect("c"); assert_eq!(actual, h); ``` -------------------------------- ### Result::is_ok() Example Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/var/type.BuildResult.html Demonstrates checking if a Result is Ok. Use this to determine if an operation succeeded. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` -------------------------------- ### FiniteFunction Cumulative Sum Example 2 Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/vec/type.FiniteFunction.html Demonstrates the cumulative sum calculation for an empty finite function. ```rust let f = FiniteFunction::::new(VecArray(vec![]), 5).unwrap(); let c = f.cumulative_sum(); assert_eq!(c.table, VecArray(vec![])); assert_eq!(c.target(), 0); ``` -------------------------------- ### Example: FiniteFunction::cumulative_sum Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/finite_function/arrow/struct.FiniteFunction.html Demonstrates the cumulative_sum method with a non-empty and an empty function, verifying the resulting cumulative sums and target values. ```rust let f = FiniteFunction::::new(VecArray(vec![3, 0, 1, 4]), 5).unwrap(); let c = f.cumulative_sum(); assert_eq!(c.table, VecArray(vec![0, 3, 3, 4])); assert_eq!(c.target(), 8); let f = FiniteFunction::::new(VecArray(vec![]), 5).unwrap(); let c = f.cumulative_sum(); assert_eq!(c.table, VecArray(vec![])); assert_eq!(c.target(), 0); ``` -------------------------------- ### Example: FiniteFunction::inject1 Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/finite_function/arrow/struct.FiniteFunction.html Asserts that calling inject1 on a function is equivalent to composing it with an injection map i1. ```rust assert_eq!(Some(f.inject1(a)), &f >> &i1); ``` -------------------------------- ### Build Example with `lax::var::Var` Helper Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/index.html Shows a more concise way to build an open hypergraph using the `Var` helper struct, which reduces boilerplate for common operations like creating nodes and defining relationships. ```rust pub fn example() { let state = OpenHypergraph::empty(); let x = Var::new(state, I8); let y = Var::new(state, I8); let (z0, z1) = (x.clone(), -(x - y)); } ``` -------------------------------- ### Example: FiniteFunction::inject0 Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/finite_function/arrow/struct.FiniteFunction.html Asserts that calling inject0 on a function is equivalent to composing it with an injection map i0. ```rust assert_eq!(Some(f.inject0(b)), &f >> &i0); ``` -------------------------------- ### Result::ok() Example Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/var/type.BuildResult.html Converts a Result into an Option, discarding the error value. Useful when you only care about the success case. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` -------------------------------- ### Result::is_ok_and() Example Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/var/type.BuildResult.html Checks if a Result is Ok and its value satisfies a predicate. Useful for conditional logic on success values. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Slice Methods Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Provides documentation for common methods available on slices, including getting the length, checking for emptiness, and accessing the first and last elements mutably or immutably. ```APIDOC ## Methods from Deref ### GET /len #### Description Returns the number of elements in the slice. #### Method GET ### Endpoint `/{self}/len` ### Response #### Success Response (200) - **usize** - The number of elements in the slice. ### GET /is_empty #### Description Returns `true` if the slice has a length of 0. #### Method GET ### Endpoint `/{self}/is_empty` ### Response #### Success Response (200) - **bool** - `true` if the slice is empty, `false` otherwise. ### GET /first #### Description Returns the first element of the slice, or `None` if it is empty. #### Method GET ### Endpoint `/{self}/first` ### Response #### Success Response (200) - **Option<&T>** - An `Option` containing a reference to the first element, or `None` if the slice is empty. ### GET /first_mut #### Description Returns a mutable reference to the first element of the slice, or `None` if it is empty. #### Method GET ### Endpoint `/{self}/first_mut` ### Response #### Success Response (200) - **Option<&mut T>** - An `Option` containing a mutable reference to the first element, or `None` if the slice is empty. ### GET /split_first #### Description Returns the first and all the rest of the elements of the slice, or `None` if it is empty. #### Method GET ### Endpoint `/{self}/split_first` ### Response #### Success Response (200) - **Option<(&T, &[T])>** - An `Option` containing a tuple of the first element and the rest of the slice, or `None` if the slice is empty. ### GET /split_first_mut #### Description Returns the first and all the rest of the elements of the slice, or `None` if it is empty. #### Method GET ### Endpoint `/{self}/split_first_mut` ### Response #### Success Response (200) - **Option<(&mut T, &mut [T])>** - An `Option` containing a mutable tuple of the first element and the rest of the slice, or `None` if the slice is empty. ### GET /split_last #### Description Returns the last and all the rest of the elements of the slice, or `None` if it is empty. #### Method GET ### Endpoint `/{self}/split_last` ### Response #### Success Response (200) - **Option<(&T, &[T])>** - An `Option` containing a tuple of the last element and the rest of the slice, or `None` if the slice is empty. ### GET /split_last_mut #### Description Returns the last and all the rest of the elements of the slice, or `None` if it is empty. #### Method GET ### Endpoint `/{self}/split_last_mut` ### Response #### Success Response (200) - **Option<(&mut T, &mut [T])>** - An `Option` containing a mutable tuple of the last element and the rest of the slice, or `None` if the slice is empty. ### GET /last #### Description Returns the last element of the slice, or `None` if it is empty. #### Method GET ### Endpoint `/{self}/last` ### Response #### Success Response (200) - **Option<&T>** - An `Option` containing a reference to the last element, or `None` if the slice is empty. ### GET /last_mut #### Description Returns a mutable reference to the last item in the slice, or `None` if it is empty. #### Method GET ### Endpoint `/{self}/last_mut` ### Response #### Success Response (200) - **Option<&mut T>** - An `Option` containing a mutable reference to the last element, or `None` if the slice is empty. ``` -------------------------------- ### Create Empty Hypergraph Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/vec/type.Hypergraph.html Constructs an empty Hypergraph with no nodes and no hyperedges. This is a starting point for building new hypergraphs. ```rust pub fn empty() -> Hypergraph ``` -------------------------------- ### Sorting an Array with sort_by Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/traits/trait.OrdArray.html Example usage of the sort_by method to reorder elements based on provided keys. ```rust use open_hypergraphs::array::{*, vec::*}; let values = VecArray(vec![10, 20, 30, 40]); let keys = VecArray(vec![3, 1, 0, 2]); let expected = VecArray(vec![30, 20, 40, 10]); let actual = values.sort_by(&keys); assert_eq!(expected, actual); ``` -------------------------------- ### Get Element Offset in Slice Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Use `element_offset` to find the index of a given element reference within a slice. This method relies on pointer arithmetic and returns `None` if the element reference is not aligned to the start of an element. ```rust let nums: &[u32] = &[1, 7, 1, 1]; let num = &nums[2]; assert_eq!(num, &1); assert_eq!(nums.element_offset(num), Some(2)); ``` ```rust let arr: &[[u32; 2]] = &[[0, 1], [2, 3]]; let flat_arr: &[u32] = arr.as_flattened(); let ok_elm: &[u32; 2] = flat_arr[0..2].try_into().unwrap(); let weird_elm: &[u32; 2] = flat_arr[1..3].try_into().unwrap(); assert_eq!(ok_elm, &[0, 1]); assert_eq!(weird_elm, &[1, 2]); assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0 assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1 ``` -------------------------------- ### Remove and Get Last Element of Slice Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Use `split_off_last` to remove the last element from an immutable slice and get a reference to it. Returns `None` if the slice is empty. ```rust let mut slice: &[_] = &['a', 'b', 'c']; let last = slice.split_off_last().unwrap(); assert_eq!(slice, &['a', 'b']); assert_eq!(last, &'c'); ``` -------------------------------- ### Remove and Get First Element of Slice Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Use `split_off_first` to remove the first element from an immutable slice and get a reference to it. Returns `None` if the slice is empty. ```rust let mut slice: &[_] = &['a', 'b', 'c']; let first = slice.split_off_first().unwrap(); assert_eq!(slice, &['b', 'c']); assert_eq!(first, &'a'); ``` -------------------------------- ### semifinite Module Overview Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/semifinite/index.html Overview of the structs, enums, and functions available in the semifinite module. ```APIDOC ## Structs ### SemifiniteFunction A function whose source is finite, but whose target may be non-finite. This is represented as an array. ## Enums ### SemifiniteArrow Arrows in the category of semifinite functions. ### SemifiniteObject Objects of arrows. ## Functions ### compose_semifinite Precompose a `FiniteFunction` with a `SemifiniteFunction`. This is also overloaded with the `>>` syntax. ``` -------------------------------- ### Remove and Get Last Element Mutably Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Use `split_off_last_mut` to remove the last element from a mutable slice and get a mutable reference to it. Returns `None` if the slice is empty. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c']; let last = slice.split_off_last_mut().unwrap(); *last = 'd'; assert_eq!(slice, &['a', 'b']); assert_eq!(last, &'d'); ``` -------------------------------- ### SemifiniteFunction Implementations Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/vec/type.SemifiniteFunction.html Provides information on the methods available for SemifiniteFunction, including constructors and utility functions. ```APIDOC ## Implementations for SemifiniteFunction ### `new(x: K::Type) -> Self` Creates a new SemifiniteFunction. ### `len(&self) -> K::I` Returns the length of the SemifiniteFunction. ### `singleton(x: T) -> SemifiniteFunction` Creates a SemifiniteFunction with a single element. ### `coproduct(&self, other: &Self) -> Self` Computes the coproduct of two SemifiniteFunctions. ``` -------------------------------- ### Remove and Get First Element Mutably Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Use `split_off_first_mut` to remove the first element from a mutable slice and get a mutable reference to it. Returns `None` if the slice is empty. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c']; let first = slice.split_off_first_mut().unwrap(); *first = 'd'; assert_eq!(slice, &['b', 'c']); assert_eq!(first, &'d'); ``` -------------------------------- ### Construct a Lax OpenHypergraph Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/index.html Demonstrates using the stateful builder interface to create nodes and edges, then unifying them to build a lax open hypergraph. ```rust use open_hypergraphs::lax::OpenHypergraph; #[derive(PartialEq, Clone)] pub enum Obj { A } #[derive(PartialEq, Clone)] pub enum Op { Copy, Mul } fn copy_mul() -> OpenHypergraph { use Obj::A; // we use the stateful builder interface to add nodes and edges to the hypergraph let mut state = OpenHypergraph::empty(); // create a `Copy : 1 → 2` operation using the `new_operation` method. // This creates nodes for each type in the input and output, and returns their `NodeId`s. let (_, (_, x)) = state.new_operation(Op::Copy, vec![A], vec![A, A]) else { // OpenHypergraph::new_operation will always turn as many sources/targets as appear in // the provided source/target types, respectively. panic!("impossible!"); }; // create a `Mul : 2 → 1` operation let (_, (y, _)) = state.new_operation(Op::Mul, vec![A, A], vec![A]) else { panic!("impossible!"); }; // Connect the copy operation to the multiply operation state.unify(x[0], y[0]); state.unify(x[1], y[1]); // return the OpenHypergraph that we built state } ``` -------------------------------- ### VecArray::type_id Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Gets the TypeId of the VecArray. ```APIDOC ## GET /vecarray/type_id ### Description Gets the `TypeId` of `self`. ### Method GET ### Endpoint /vecarray/type_id ### Response #### Success Response (200) - **TypeId** - The unique identifier for the type of the VecArray. #### Response Example ```json { "result": "a1b2c3d4-e5f6-7890-1234-567890abcdef" } ``` ``` -------------------------------- ### Build Full Adder Circuit with Var Operators Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/var/index.html Demonstrates using Var's overloaded operators like `^` (XOR) and `&` (AND) to construct a full adder circuit. Each operation on a Var creates a new node in the OpenHypergraph. ```rust fn full_adder(a: Var, b: Var, cin: Var) -> (Var, Var) { let a_xor_b = a.clone() ^ b.clone(); let a_and_b = a & b; (a_xor_b, a_and_b) } ``` -------------------------------- ### Create Initial IndexedCoproduct Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/indexed_coproduct/struct.IndexedCoproduct.html Creates the initial object for an IndexedCoproduct, representing the finite coproduct indexed by the empty set. The target of `sources` must be zero for laws to hold. ```rust pub fn initial(target: K::I) -> Self ``` -------------------------------- ### Get Length of Operations Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/operations/struct.Operations.html Returns the number of operations in the list. ```rust pub fn len(&self) -> K::I ``` -------------------------------- ### Coproduct initial Method Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/category/trait.Coproduct.html Constructs the initial arrow `initial_a : 0 → a` from some object `a`. ```rust fn initial(a: Self::Object) -> Self; ``` -------------------------------- ### VecArray::arange Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Creates a VecArray with a sequence of indices from start to stop. ```APIDOC ## POST /vecarray/arange ### Description Creates a VecArray with a sequence of indices from start to stop. ### Method POST ### Endpoint /vecarray/arange ### Request Body - **start** (usize) - The starting index (inclusive). - **stop** (usize) - The stopping index (exclusive). ### Response #### Success Response (200) - **Self** - A VecArray containing the range of indices. #### Response Example ```json { "result": [0, 1, 2, 3, 4] } ``` ``` -------------------------------- ### Iterate Over Slice Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Returns an iterator over the slice, yielding all items from start to end. ```APIDOC ## GET /slice/iter ### Description Returns an iterator over the slice. The iterator yields all items from start to end. ### Method GET ### Endpoint /slice/iter ### Parameters #### Query Parameters - **slice** (array) - Required - The slice to iterate over ### Response #### Success Response (200) - **iterator** (object) - An iterator object representing the slice elements #### Response Example ```json { "iterator": [ 1, 2, 4 ] } ``` ``` -------------------------------- ### Construct an OpenHypergraph with build Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/var/fn.build.html Use this function to initialize an OpenHypergraph by providing a closure that returns source and target variable lists. ```rust pub fn build(f: F) -> BuildResult where F: Fn(&Rc>>) -> (Vec>, Vec>), ``` -------------------------------- ### Get Length of IndexedCoproduct Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/indexed_coproduct/struct.IndexedCoproduct.html Returns the length of the IndexedCoproduct, which corresponds to the number of segments. ```rust pub fn len(&self) -> K::I ``` -------------------------------- ### SemifiniteFunction Methods Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/semifinite/struct.SemifiniteFunction.html Core methods for creating and manipulating SemifiniteFunction instances. ```APIDOC ## SemifiniteFunction Methods ### Description Methods for initializing and performing operations on SemifiniteFunction structures. ### Methods - **new(x: K::Type) -> Self**: Creates a new SemifiniteFunction from an array. - **len(&self) -> K::I**: Returns the length of the function source. - **singleton(x: T) -> SemifiniteFunction**: Creates a SemifiniteFunction containing a single element. - **coproduct(&self, other: &Self) -> Self**: Computes the coproduct of two SemifiniteFunctions. ``` -------------------------------- ### rchunks(chunk_size) Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Returns an iterator over chunks of a specified size, starting from the end of the slice. ```APIDOC ## pub fn rchunks(&self, chunk_size: usize) -> RChunks<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. ### Method `rchunks` ### Endpoint N/A (Method on slice) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let slice = ['l', 'o', 'r', 'e', 'm']; let mut iter = slice.rchunks(2); assert_eq!(iter.next().unwrap(), &['e', 'm']); assert_eq!(iter.next().unwrap(), &['o', 'r']); assert_eq!(iter.next().unwrap(), &['l']); assert!(iter.next().is_none()); ``` ### Response #### Success Response (200) An iterator yielding slices of up to `chunk_size` elements, starting from the end. #### Response Example ```rust // Example based on the provided code snippet // The actual return type is an iterator, not a JSON object. // For illustrative purposes, imagine the structure of yielded items: // & [T] ``` ##### §Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### Inserting into a Sorted Vector with `partition_point` Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Shows how to use `partition_point` to find the correct insertion index for an element in a sorted vector to maintain sort order. Using `<=` in the predicate can minimize element shifting. ```rust let mut s = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; let num = 42; let idx = s.partition_point(|&x| x <= num); // If `num` is unique, `s.partition_point(|&x| x < num)` (with `<`) is equivalent to // `s.binary_search(&num).unwrap_or_else(|x| x)`, but using `<=` will allow `insert` // to shift less elements. s.insert(idx, num); assert_eq!(s, [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]); ``` -------------------------------- ### GET subslice_range Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Returns the range of indices that a subslice points to within the parent slice. ```APIDOC ## GET subslice_range ### Description Returns the range of indices that a subslice points to. This is a nightly-only experimental API. ### Method GET ### Parameters #### Request Body - **subslice** (&[T]) - Required - The subslice to locate. ### Response #### Success Response (200) - **range** (Option>) - The range of indices corresponding to the subslice. ``` -------------------------------- ### GET element_offset Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Returns the index that an element reference points to using pointer arithmetic. ```APIDOC ## GET element_offset ### Description Returns the index that an element reference points to. Returns None if the element does not point to the start of an element within the slice. ### Method GET ### Parameters #### Request Body - **element** (&T) - Required - The element reference to locate within the slice. ### Response #### Success Response (200) - **index** (Option) - The index of the element if found. ``` -------------------------------- ### Finding Range of Matching Elements with `partition_point` Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Illustrates using `partition_point` to find the range of elements equal to a specific value in a sorted slice. It also shows how `partition_point` behaves for values not present in the slice. ```rust let s = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; let low = s.partition_point(|x| x < &1); assert_eq!(low, 1); let high = s.partition_point(|x| x <= &1); assert_eq!(high, 5); let r = s.binary_search(&1); assert!((low..high).contains(&r.unwrap())); assert!(s[..low].iter().all(|&x| x < 1)); assert!(s[low..high].iter().all(|&x| x == 1)); assert!(s[high..].iter().all(|&x| x > 1)); // For something not found, the "range" of equal items is empty assert_eq!(s.partition_point(|x| x < &11), 9); assert_eq!(s.partition_point(|x| x <= &11), 9); assert_eq!(s.binary_search(&11), Err(9)); ``` -------------------------------- ### Get Additive Identity of SemifiniteFunction Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/vec/type.SemifiniteFunction.html Returns the additive identity element (zero) for SemifiniteFunction. ```rust fn zero() -> Self ``` -------------------------------- ### FiniteFunction Construction and Operations Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/finite_function/arrow/struct.FiniteFunction.html Methods for creating and manipulating FiniteFunction instances. ```APIDOC ## POST /finite_function/new ### Description Construct a new FiniteFunction from a table of indices and a target size. ### Method POST ### Parameters #### Request Body - **table** (K::Index) - Required - The array of indices. - **target** (K::I) - Required - The target size of the function. ### Response #### Success Response (200) - **FiniteFunction** (Object) - The constructed FiniteFunction instance. --- ## GET /finite_function/constant ### Description Construct the constant finite function f : a → x + 1 + b, mapping all elements to x. ### Method GET ### Parameters #### Query Parameters - **a** (K::I) - Required - Domain size. - **x** (K::I) - Required - The constant value to map to. - **b** (K::I) - Required - Offset for the target size. --- ## GET /finite_function/is_injective ### Description Check if the finite function is injective. ### Method GET ### Response #### Success Response (200) - **is_injective** (bool) - Returns true if the function is injective. ``` -------------------------------- ### rchunks_exact(chunk_size) Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Returns an iterator over chunks of exactly `chunk_size` elements, starting from the end of the slice. ```APIDOC ## pub fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. If `chunk_size` does not divide the length of the slice, then the last up to `chunk_size-1` elements will be omitted and can be retrieved from the `remainder` function of the iterator. ### Method `rchunks_exact` ### Endpoint N/A (Method on slice) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example demonstrating rchunks_exact usage (conceptual) // let slice = [1, 2, 3, 4, 5]; // let mut iter = slice.rchunks_exact(2); // assert_eq!(iter.next().unwrap(), &[3, 4]); // assert_eq!(iter.next().unwrap(), &[1, 2]); // assert!(iter.next().is_none()); // let remainder = iter.remainder(); // This would be &[5] ``` ### Response #### Success Response (200) An iterator yielding slices of exactly `chunk_size` elements, starting from the end. The iterator also provides access to any remaining elements. #### Response Example ```rust // Example based on the provided code snippet // The actual return type is an iterator, not a JSON object. // For illustrative purposes, imagine the structure of yielded items: // & [T] ``` ##### §Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### rchunks_mut(chunk_size) Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Returns a mutable iterator over chunks of a specified size, starting from the end of the slice. ```APIDOC ## pub fn rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are mutable slices, and do not overlap. ### Method `rchunks_mut` ### Endpoint N/A (Method on slice) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let v = &mut [0, 0, 0, 0, 0]; let mut count = 1; for chunk in v.rchunks_mut(2) { for elem in chunk.iter_mut() { *elem += count; } count += 1; } assert_eq!(v, &[3, 2, 2, 1, 1]); ``` ### Response #### Success Response (200) An iterator yielding mutable slices of up to `chunk_size` elements, starting from the end. #### Response Example ```rust // Example based on the provided code snippet // The actual return type is an iterator, not a JSON object. // For illustrative purposes, imagine the structure of yielded items: // &mut [T] ``` ##### §Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### FiniteFunction Implementations Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/vec/type.FiniteFunction.html Provides details on the methods available for the FiniteFunction struct. ```APIDOC ## Implementations for FiniteFunction ### `impl FiniteFunction` #### `pub fn is_injective(&self) -> bool` Check if this finite function is injective. #### `pub fn has_disjoint_image(&self, other: &Self) -> bool` Check whether `self` and `other` have disjoint images in a common codomain. Domains may differ. Returns `true` exactly when `image(self) ∩ image(other) = ∅`. Returns `false` when codomains differ. ### `impl FiniteFunction` #### `pub fn new(table: K::Index, target: K::I) -> Option>` Construct a FiniteFunction from a table of indices. #### `pub fn terminal(a: K::I) -> Self` The length-`a` array of zeroes `!_a : a → 1`. #### `pub fn constant(a: K::I, x: K::I, b: K::I) -> Self` Construct the constant finite function `f : a → x + 1 + b`, an array of length `a` mapping all elements to `x`. The target of the finite function must be at least `x+1` to be valid. This is equivalent to `!_a ; ι₁ ; ι₀`. ```rust let (x, a, b) = (2, 3, 2); let actual = FiniteFunction::::constant(a, x, b); let expected = FiniteFunction::new(VecArray(vec![2, 2, 2]), x + b + 1).unwrap(); assert_eq!(actual, expected); // Check equal to `!_a ; ι₁ ; ι₀` let i1 = FiniteFunction::::inj1(x, 1); let i0 = FiniteFunction::inj0(x + 1, b); let f = FiniteFunction::terminal(a); let h = f.compose(&i1).expect("b").compose(&i0).expect("c"); assert_eq!(actual, h); ``` #### `pub fn inject0(&self, b: K::I) -> FiniteFunction` Directly construct `f ; ι₀` instead of computing by composition. ```rust assert_eq!(Some(f.inject0(b)), &f >> &i0); ``` #### `pub fn inject1(&self, a: K::I) -> FiniteFunction` Directly construct `f ; ι₁` instead of computing by composition. ```rust assert_eq!(Some(f.inject1(a)), &f >> &i1); ``` #### `pub fn to_initial(&self) -> FiniteFunction` Given a finite function `f : A → B`, return the initial map `initial : 0 → B`. #### `pub fn coequalizer(&self, other: &Self) -> Option>` #### `pub fn coequalizer_universal(&self, f: &Self) -> Option` #### `pub fn transpose(a: K::I, b: K::I) -> FiniteFunction` `transpose(a, b)` is the “transposition permutation” for an `a → b` matrix stored in row-major order. Let M be an `a*b`-dimensional input thought of as a matrix in row-major order – having `b` rows and `a` columns. Then `transpose(a, b)` computes the “target indices” of the transpose. So for matrices `M : a → b` and `N : b → a`, setting the indices `N[transpose(a, b)] = M` is the same as writing `N = M.T`. #### `pub fn injections(&self, a: &FiniteFunction) -> Option` Given a finite function `s : N → K` representing the objects of the finite coproduct `Σ_{n ∈ N} s(n)` whose injections have the type `ι_x : s(x) → Σ_{n ∈ N} s(n)`, and given a finite map `a : A → N`, compute the coproduct of injections `injections(s, a) : Σ_{x ∈ A} s(x) → Σ_{n ∈ N} s(n)`. `injections(s, a) = Σ_{x ∈ A} ι_a(x)`. So that `injections(s, id) == id`. Note that when `a` is a permutation, `injections(s, a)` is a “blockwise” version of that permutation with block sizes equal to `s`. #### `pub fn cumulative_sum(&self) -> Self` Given a finite function `f : A → B`, compute the cumulative sum of `f`, a finite function `cumulative_sum(f) : A → sum_i(f())`. ```rust let f = FiniteFunction::::new(VecArray(vec![3, 0, 1, 4]), 5).unwrap(); let c = f.cumulative_sum(); assert_eq!(c.table, VecArray(vec![0, 3, 3, 4])); assert_eq!(c.target(), 8); let f = FiniteFunction::::new(VecArray(vec![]), 5).unwrap(); let c = f.cumulative_sum(); assert_eq!(c.table, VecArray(vec![])); assert_eq!(c.target(), 0); ``` ``` -------------------------------- ### array_windows Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Returns an iterator over overlapping windows of `N` elements from the slice, starting from the beginning. ```APIDOC ## pub fn array_windows(&self) -> ArrayWindows<'_, T, N> ### Description Returns an iterator over overlapping windows of `N` elements of a slice, starting at the beginning of the slice. This is the const generic equivalent of `windows`. ### Method `array_windows` ### Endpoint N/A (Method on slice) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let slice = [0, 1, 2, 3]; let mut iter = slice.array_windows(); assert_eq!(iter.next().unwrap(), &[0, 1]); assert_eq!(iter.next().unwrap(), &[1, 2]); assert_eq!(iter.next().unwrap(), &[2, 3]); assert!(iter.next().is_none()); ``` ### Response #### Success Response (200) An iterator yielding slices of `N` elements, representing overlapping windows. #### Response Example ```rust // Example based on the provided code snippet // The actual return type is an iterator, not a JSON object. // For illustrative purposes, imagine the structure of yielded items: // &[T; N] ``` ##### §Panics Panics if `N` is zero. ``` -------------------------------- ### pub const fn into_ok(self) -> T Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/var/type.BuildResult.html Returns the contained Ok value, but never panics. ```APIDOC ## pub const fn into_ok(self) -> T ### Description Returns the contained Ok value, but never panics. This method is known to never panic on the result types it is implemented for. ### Response - **T** (Value) - The contained Ok value. ``` -------------------------------- ### as_rchunks Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Splits a slice into a remainder slice and a slice of N-element arrays, starting from the end of the slice. ```APIDOC ## pub fn as_rchunks(&self) -> (&[T], &[[T; N]]) ### Description Splits the slice into a slice of `N`-element arrays, starting at the end of the slice, and a remainder slice with length strictly less than `N`. ### Method GET (conceptual, as this is a method on a slice) ### Endpoint N/A (method on slice) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let slice = ['l', 'o', 'r', 'e', 'm']; let (remainder, chunks) = slice.as_rchunks::<2>(); assert_eq!(remainder, &['l']); assert_eq!(chunks, &[['o', 'r'], ['e', 'm']]); ``` ### Response #### Success Response (200) Returns a tuple containing two slices: the first is the remainder slice, and the second is a slice of `N`-element arrays. #### Response Example ```rust // For input: ['l', 'o', 'r', 'e', 'm'] with N=2 // Output: (&['l'], &[['o', 'r'], ['e', 'm']]) ``` ##### §Panics Panics if `N` is zero. ``` -------------------------------- ### Get Target of OpenHypergraph Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/open_hypergraph/struct.OpenHypergraph.html Retrieves the target SemifiniteFunction of an OpenHypergraph. Represents the output boundary of the hypergraph. ```rust pub fn target(&self) -> SemifiniteFunction ``` -------------------------------- ### IndexedCoproduct Methods Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/indexed_coproduct/struct.IndexedCoproduct.html Key methods for creating and manipulating IndexedCoproduct instances. ```APIDOC ## Methods ### new Creates a new IndexedCoproduct from a FiniteFunction whose target is the sum of its elements. ### singleton Constructs a segmented array with a single segment containing values. ### elements Constructs a segmented array with values.len() segments, each containing a single element. ### flatmap Composes two IndexedCoproducts, treating them as lists-of-lists. ### map_values Maps the values array of an indexed coproduct, leaving the sources unchanged. ``` -------------------------------- ### Get Source of OpenHypergraph Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/open_hypergraph/struct.OpenHypergraph.html Retrieves the source SemifiniteFunction of an OpenHypergraph. Represents the input boundary of the hypergraph. ```rust pub fn source(&self) -> SemifiniteFunction ``` -------------------------------- ### Implement CloneToUninit for T Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/var/forget/struct.Forget.html Provides an experimental nightly-only implementation of CloneToUninit for types that implement Clone. This allows for unsafe copying to uninitialized memory. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Get a contiguous subrange of the array Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecKind.html Retrieves a slice of the underlying vector using range bounds. ```rust use open_hypergraphs::array::{*, vec::*}; let v = VecArray(vec![0, 1, 2, 3, 4]); assert_eq!(v.get_range(..), &[0, 1, 2, 3, 4]); assert_eq!(v.get_range(..v.len()), &[0, 1, 2, 3, 4]); ``` -------------------------------- ### Core Modules Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/strict/index.html Overview of the primary modules available within the open-hypergraphs crate. ```APIDOC ## Core Modules - **eval**: An array-backend-agnostic evaluator. - **functor**: Functors between categories of open hypergraphs. - **graph**: Graph-related structures. - **hypergraph**: The category of hypergraphs with objects represented by `Hypergraph` and arrows by `arrow::HypergraphArrow`. - **layer**: A Coffman-Graham-inspired layering algorithm. - **open_hypergraph**: The primary datastructure for representing cospans of hypergraphs. - **relation**: Indexed coproducts as relations. - **vec**: Type aliases for strict Open Hypergraphs using the `VecKind` array backend. ``` -------------------------------- ### Result::is_err() Example Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/lax/var/type.BuildResult.html Demonstrates checking if a Result is Err. Use this to determine if an operation failed. ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Initialize Vec Elements via Raw Pointer Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Demonstrates initializing vector elements using raw pointer writes after allocating capacity. Requires unsafe block. ```rust let size = 4; let mut x: Vec = Vec::with_capacity(size); let x_ptr = x.as_mut_ptr(); // Initialize elements via raw pointer writes, then set length. unsafe { for i in 0..size { *x_ptr.add(i) = i as i32; } x.set_len(size); } assert_eq!(&*x, &[0, 1, 2, 3]); ``` -------------------------------- ### Split slice from end with rsplitn Source: https://docs.rs/open-hypergraphs/0.3.1/open_hypergraphs/array/vec/struct.VecArray.html Splits a slice into at most n items starting from the end based on a predicate. ```rust let v = [10, 40, 30, 20, 60, 50]; for group in v.rsplitn(2, |num| *num % 3 == 0) { println!("{group:?}"); } ```