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// For reproducibility, we need explicitly ordered semantics in our collections.
26// Accordingly, we swap out the stdlib collections for those provided by `indexmap`.
27// Since we're swapping out these types already, we can benefit from a hash function
28// that is optimized for small collections.
29
30pub(crate) type HashMap<K, V> = indexmap::IndexMap<K, V, rustc_hash::FxBuildHasher>;
31pub(crate) type HashSet<T> = indexmap::IndexSet<T, rustc_hash::FxBuildHasher>;
32
33use std::{hash::Hash, ops::Deref};
34
35/// A simple wrapper around the auction input so we do not leak implementation details
36#[cfg_attr(
37    feature = "serde",
38    derive(serde::Serialize, serde::Deserialize),
39    serde(transparent),
40    serde(bound = "
41        BidderId: Hash + Eq + serde::Serialize + serde::de::DeserializeOwned,
42        PortfolioId: Clone + Hash + Eq + serde::Serialize + serde::de::DeserializeOwned,
43        ProductId: Hash + Eq + Ord + serde::Serialize + serde::de::DeserializeOwned
44    ")
45)]
46pub struct Auction<BidderId, PortfolioId, ProductId>(
47    HashMap<BidderId, Submission<PortfolioId, ProductId>>,
48);
49
50impl<BidderId, PortfolioId, ProductId> Deref for Auction<BidderId, PortfolioId, ProductId> {
51    type Target = HashMap<BidderId, Submission<PortfolioId, ProductId>>;
52
53    fn deref(&self) -> &Self::Target {
54        &self.0
55    }
56}
57
58impl<BidderId: Hash + Eq, PortfolioId, ProductId>
59    FromIterator<(BidderId, Submission<PortfolioId, ProductId>)>
60    for Auction<BidderId, PortfolioId, ProductId>
61{
62    fn from_iter<T: IntoIterator<Item = (BidderId, Submission<PortfolioId, ProductId>)>>(
63        iter: T,
64    ) -> Self {
65        Self(HashMap::<BidderId, Submission<PortfolioId, ProductId>>::from_iter(iter))
66    }
67}