fts_solver/
lib.rs

1#![warn(missing_docs)]
2// Note: this overwrites the link in the README to point to the rust docs of the fts-demo crate.
3//! [fts_core]: https://docs.rs/fts_core/latest/fts_core/index.html
4//! [fts_server]: https://docs.rs/fts_server/latest/fts_server/index.html
5//! [fts_solver]: https://docs.rs/fts_solver/latest/fts_solver/index.html
6//! [fts_demo]: https://docs.rs/fts_demo/latest/fts_demo/index.html
7#![doc = include_str!("../README.md")]
8
9/**
10 * The various solver implementations.
11 */
12mod impls;
13pub use impls::*;
14
15/**
16 * The core data types the solver implementations operate on.
17 */
18mod types;
19pub use types::*;
20
21/// Utilities for testing and CLI interface to the solver
22#[cfg(feature = "io")]
23pub mod io;
24
25/// Utilities for converting the derived QP to standard file formats
26pub mod export;
27
28// For reproducibility, we need explicitly ordered semantics in our collections.
29// Accordingly, we swap out the stdlib collections for those provided by `indexmap`.
30// Since we're swapping out these types already, we can benefit from a hash function
31// that is optimized for small collections.
32
33pub(crate) type HashMap<K, V> = indexmap::IndexMap<K, V, rustc_hash::FxBuildHasher>;
34pub(crate) type HashSet<T> = indexmap::IndexSet<T, rustc_hash::FxBuildHasher>;
35
36use std::{hash::Hash, ops::Deref};
37
38/// A simple wrapper around the auction input so we do not leak implementation details
39#[cfg_attr(
40    feature = "serde",
41    derive(serde::Serialize, serde::Deserialize),
42    serde(transparent),
43    serde(bound = "
44        BidderId: Hash + Eq + serde::Serialize + serde::de::DeserializeOwned,
45        PortfolioId: Clone + Hash + Eq + serde::Serialize + serde::de::DeserializeOwned,
46        ProductId: Hash + Eq + Ord + serde::Serialize + serde::de::DeserializeOwned
47    ")
48)]
49pub struct Auction<BidderId, PortfolioId, ProductId>(
50    HashMap<BidderId, Submission<PortfolioId, ProductId>>,
51);
52
53impl<BidderId, PortfolioId, ProductId> Deref for Auction<BidderId, PortfolioId, ProductId> {
54    type Target = HashMap<BidderId, Submission<PortfolioId, ProductId>>;
55
56    fn deref(&self) -> &Self::Target {
57        &self.0
58    }
59}
60
61impl<BidderId: Hash + Eq, PortfolioId, ProductId>
62    FromIterator<(BidderId, Submission<PortfolioId, ProductId>)>
63    for Auction<BidderId, PortfolioId, ProductId>
64{
65    fn from_iter<T: IntoIterator<Item = (BidderId, Submission<PortfolioId, ProductId>)>>(
66        iter: T,
67    ) -> Self {
68        Self(HashMap::<BidderId, Submission<PortfolioId, ProductId>>::from_iter(iter))
69    }
70}