diff --git a/core/Cargo.toml b/core/Cargo.toml index c47759c..2cc3d6e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -3,8 +3,13 @@ name = "codd" version = "0.1.0" authors = ["Salman Saghafi "] edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +license = "MIT" +description = "codd is a minimal in-memory database with relational algebraic expressions as queries." +homepage = "https://github.com/salmans/codd" +repository = "https://github.com/salmans/codd" +keywords = ["codd", "relational-algebra", "database"] +categories = ["mathematics", "database-implementations"] +readme = "../README.md" [dependencies] thiserror = "^1.0" diff --git a/core/src/database.rs b/core/src/database.rs index a677207..f6dbfd8 100644 --- a/core/src/database.rs +++ b/core/src/database.rs @@ -126,8 +126,7 @@ impl Clone for ViewEntry { } } -/// Is a database that stores tuples in relation instances and offers and maintains views -/// over its data. +/// Stores data in relation instances and implements incremental view maintenance over them. /// /// **Example**: /// ```rust @@ -187,8 +186,10 @@ impl Database { expression.collect_recent(&evaluate::Evaluator::new(self)) } - /// Adds a new relation instance identified by `name` to the database and returns the a - /// corresponding `Relation` object. + /// Adds a new relation instance identified by `name` to the database and returns a + /// [`Relation`] object that can be used to access the instance. + /// + /// [`Relation`]: ./expression/struct.Relation.html pub fn add_relation(&mut self, name: &str) -> Result, Error> where T: Tuple + 'static, @@ -202,7 +203,7 @@ impl Database { } } - /// Inserts tuples in the relation `Instance` for `relation`. + /// Inserts tuples in the `Instance` corresponding to `relation`. pub fn insert(&self, relation: &Relation, tuples: Tuples) -> Result<(), Error> where T: Tuple + 'static, @@ -227,7 +228,8 @@ impl Database { Ok(result) } - /// Stores a new view over `expression` and returns the corresponding [`View`] expression. + /// Stores a new view over `expression` and returns a [`View`] objeect that can be + /// evaluated as a view. /// /// [`View`]: ./expression/struct.View.html pub fn store_view(&mut self, expression: I) -> Result, Error> @@ -247,17 +249,17 @@ impl Database { // track relation dependencies of this view: for r in relation_deps.into_iter() { - self.relations - .get_mut(&r) - .map(|rs| rs.add_dependent_view(reference.clone())); + if let Some(rs) = self.relations.get_mut(&r) { + rs.add_dependent_view(reference.clone()) + } entry.dependee_relations.insert(r); } // track view dependencies of this view: for r in view_deps.into_iter() { - self.views - .get_mut(&r) - .map(|rs| rs.add_dependent_view(reference.clone())); + if let Some(rs) = self.views.get_mut(&r) { + rs.add_dependent_view(reference.clone()) + } entry.dependee_views.insert(r.clone()); } @@ -342,6 +344,12 @@ impl Database { } } +impl Default for Database { + fn default() -> Self { + Self::new() + } +} + impl Clone for Database { fn clone(&self) -> Self { let mut relations = HashMap::new(); diff --git a/core/src/database/evaluate.rs b/core/src/database/evaluate.rs index 30c5f0a..ddc2232 100644 --- a/core/src/database/evaluate.rs +++ b/core/src/database/evaluate.rs @@ -276,7 +276,7 @@ impl<'d> StableCollector for IncrementalCollector<'d> { where T: Tuple, { - Ok(Vec::new().into()) + Ok(Vec::new()) } fn collect_singleton(&self, singleton: &Singleton) -> Result>, Error> diff --git a/core/src/database/helpers.rs b/core/src/database/helpers.rs index e87a37c..d85ef26 100644 --- a/core/src/database/helpers.rs +++ b/core/src/database/helpers.rs @@ -5,19 +5,19 @@ /// [`datafrog`]: https://github.com/rust-lang/datafrog #[inline(always)] pub(crate) fn gallop(mut slice: &[T], mut cmp: impl FnMut(&T) -> bool) -> &[T] { - if slice.len() > 0 && cmp(&slice[0]) { + if !slice.is_empty() && cmp(&slice[0]) { let mut step = 1; while step < slice.len() && cmp(&slice[step]) { slice = &slice[step..]; - step = step << 1; + step <<= 1; } - step = step >> 1; + step >>= 1; while step > 0 { if step < slice.len() && cmp(&slice[step]) { slice = &slice[step..]; } - step = step >> 1; + step >>= 1; } slice = &slice[1..]; @@ -73,8 +73,8 @@ pub(crate) fn join_helper( let count2 = slice2.iter().take_while(|x| x.0 == slice2[0].0).count(); for index1 in 0..count1 { - for index2 in 0..count2 { - result(&slice1[0].0, &slice1[index1].1, &slice2[index2].1); + for item in slice2.iter().take(count2) { + result(&slice1[0].0, &slice1[index1].1, &item.1); } } @@ -117,19 +117,19 @@ pub(crate) fn diff_helper(left: &[T], right: &[&[T]], mut result: impl F for tuple in left { let mut to_add = true; - for i in 0..right.len() { + for mut to_find in &mut right { use std::cmp::Ordering; - if !right[i].is_empty() { - match tuple.cmp(&right[i][0]) { + if !to_find.is_empty() { + match tuple.cmp(&to_find[0]) { Ordering::Less => {} Ordering::Equal => { - right[i] = &right[i][1..]; to_add = false; } Ordering::Greater => { - right[i] = &gallop(right[i], |x| x < &tuple); - if !right[i].is_empty() && tuple == &right[i][0] { + let mut temp = gallop(to_find, |x| x < tuple); + to_find = &mut temp; + if !to_find.is_empty() && tuple == &to_find[0] { to_add = false; } } diff --git a/core/src/database/instance.rs b/core/src/database/instance.rs index 07c653e..a237e2a 100644 --- a/core/src/database/instance.rs +++ b/core/src/database/instance.rs @@ -7,7 +7,7 @@ use std::{ rc::Rc, }; -/// Is a wrapper around a vector of tuples. As an invariant, tuples of `Tuples` are sorted. +/// Is a wrapper around a vector of tuples. As an invariant, the content of `Tuples` is sorted. /// /// **Note**: `Tuples` is borrowed from `Relation` in [`datafrog`]. /// @@ -196,7 +196,7 @@ where let mut slice = &batch[..]; to_add.items.retain(|x| { slice = gallop(slice, |y| y < x); - slice.len() == 0 || &slice[0] != x + slice.is_empty() || &slice[0] != x }); } *self.recent.borrow_mut() = to_add; diff --git a/core/src/expression.rs b/core/src/expression.rs index 6be82a7..db1da7c 100644 --- a/core/src/expression.rs +++ b/core/src/expression.rs @@ -1,9 +1,4 @@ -/*! Defines relational algebraic expressions as generic over [`Tuple`] types and -can be evaluated in [`Database`]. - -[`Tuple`]: ../trait.Tuple.html -[`Database`]: ./database/struct.Database.html -*/ +/*! Defines relational algebraic expressions as generic types over `Tuple` types.*/ mod builder; pub(crate) mod dependency; mod difference; @@ -36,16 +31,16 @@ pub use singleton::Singleton; pub use union::Union; pub use view::View; -/// Is the trait of expressions in relational algebra that can be evaluated in -/// a database. +/// Is the trait of expressions in relational algebra that can be evaluated in a database. pub trait Expression: Clone + std::fmt::Debug { - /// Visits this node by a [`Visitor`]. + /// Visits this expression by a [`Visitor`]. /// /// [`Visitor`]: ./trait.Visitor.html fn visit(&self, visitor: &mut V) where V: Visitor; + /// Returns an expression builder over this expression. fn builder(&self) -> Builder { Builder::from(self.clone()) } @@ -99,8 +94,9 @@ where } } -/// Is the trait of objects that visit [`Expression`]s. The default implementation guides -/// the visitor through all subexpressions of the expressions that is visited. +/// Is the trait of objects that visit sub-expressions of an [`Expression`]. The default +/// implementation guides the visitor through all sub-expressions of the expressions that +/// is visited. /// /// [`Expression`]: ./trait.Expression.html pub trait Visitor: Sized { diff --git a/core/src/expression/builder.rs b/core/src/expression/builder.rs index b3698cc..ebe5d43 100644 --- a/core/src/expression/builder.rs +++ b/core/src/expression/builder.rs @@ -2,7 +2,7 @@ use super::*; use crate::Tuple; use std::marker::PhantomData; -/// Is a builder for building [`Expression`]s. +/// Is a builder for building [`Expression`] values. /// /// [`Expression`]: ./trait.Expression.html pub struct Builder @@ -227,7 +227,7 @@ where /// /// assert_eq!(vec!["Apple0", "Cherry4"], db.evaluate(&join).unwrap().into_tuples()); /// ``` - pub fn with_key<'k, K>(self, f: impl FnMut(&L) -> K + 'static) -> WithKeyBuilder + pub fn with_key(self, f: impl FnMut(&L) -> K + 'static) -> WithKeyBuilder where K: Tuple, { diff --git a/core/src/expression/difference.rs b/core/src/expression/difference.rs index 4fabf71..b48c0a4 100644 --- a/core/src/expression/difference.rs +++ b/core/src/expression/difference.rs @@ -2,7 +2,7 @@ use super::{view::ViewRef, Expression, IntoExpression, Visitor}; use crate::Tuple; use std::marker::PhantomData; -/// Evaluates to all tuples that are in `left` but not in `right` (`left - right`). +/// Evaluates to the tuples that are in its `left` but not in its `right` sub-expressions (`left - right`). /// /// **Example**: /// ```rust @@ -59,33 +59,33 @@ where let (relation_deps, view_deps) = deps.into_dependencies(); Self { - left: left.clone(), - right: right.clone(), + left, + right, relation_deps: relation_deps.into_iter().collect(), view_deps: view_deps.into_iter().collect(), _marker: PhantomData, } } - /// Returns a reference to the expression on left. + /// Returns a reference to the left sub-expression. #[inline(always)] pub fn left(&self) -> &L { &self.left } - /// Returns a reference to the expression on right. + /// Returns a reference to the right sub-expression. #[inline(always)] pub fn right(&self) -> &R { &self.right } - /// Returns a reference to relation dependencies of the receiver. + /// Returns a reference to the relation dependencies of the receiver. #[inline(always)] pub(crate) fn relation_deps(&self) -> &[String] { &self.relation_deps } - /// Returns a reference to view dependencies of the receiver. + /// Returns a reference to the view dependencies of the receiver. #[inline(always)] pub(crate) fn view_deps(&self) -> &[ViewRef] { &self.view_deps diff --git a/core/src/expression/empty.rs b/core/src/expression/empty.rs index aeed271..550bec5 100644 --- a/core/src/expression/empty.rs +++ b/core/src/expression/empty.rs @@ -44,3 +44,9 @@ where visitor.visit_empty(&self); } } + +impl Default for Empty { + fn default() -> Self { + Self::new() + } +} diff --git a/core/src/expression/full.rs b/core/src/expression/full.rs index 1e708b5..fbcf675 100644 --- a/core/src/expression/full.rs +++ b/core/src/expression/full.rs @@ -2,7 +2,7 @@ use super::{Expression, Visitor}; use crate::Tuple; use std::marker::PhantomData; -/// Is a placeholder for a "full" instance, containing *all* tuples of type `T`. +/// Is a placeholder for a "full" instance, containing *all* tuples of its type. /// /// **Note**: because `Full` expression cannot be described by a range-restricted /// (see [chapter 2] of Foundations of Databases) query, any query containing @@ -50,3 +50,9 @@ where visitor.visit_full(&self); } } + +impl Default for Full { + fn default() -> Self { + Self::new() + } +} diff --git a/core/src/expression/intersect.rs b/core/src/expression/intersect.rs index 42f06a8..b7b6981 100644 --- a/core/src/expression/intersect.rs +++ b/core/src/expression/intersect.rs @@ -2,7 +2,7 @@ use super::{view::ViewRef, Expression, IntoExpression, Visitor}; use crate::Tuple; use std::marker::PhantomData; -/// Evaluates to all tuples that are in both `left` and `right` expressions. +/// Evaluates to all tuples that are in its both `left` and `right` sub-expressions. /// /// **Example**: /// ```rust @@ -55,33 +55,33 @@ where let (relation_deps, view_deps) = deps.into_dependencies(); Self { - left: left.clone(), - right: right.clone(), + left, + right, relation_deps: relation_deps.into_iter().collect(), view_deps: view_deps.into_iter().collect(), _marker: PhantomData, } } - /// Returns a reference to the expression on left. + /// Returns a reference to the left sub-expression. #[inline(always)] pub fn left(&self) -> &L { &self.left } - /// Returns a reference to the expression on right. + /// Returns a reference to the right sub-expression. #[inline(always)] pub fn right(&self) -> &R { &self.right } - /// Returns a reference to relation dependencies of the receiver. + /// Returns a reference to the relation dependencies of the receiver. #[inline(always)] pub(crate) fn relation_deps(&self) -> &[String] { &self.relation_deps } - /// Returns a reference to view dependencies of the receiver. + /// Returns a reference to the view dependencies of the receiver. #[inline(always)] pub(crate) fn view_deps(&self) -> &[ViewRef] { &self.view_deps diff --git a/core/src/expression/join.rs b/core/src/expression/join.rs index e02ba7d..1ad933d 100644 --- a/core/src/expression/join.rs +++ b/core/src/expression/join.rs @@ -6,7 +6,11 @@ use std::{ rc::Rc, }; -/// Is the join of `left` and `right` expressions. +/// Is the type of `Join` mapping closures for constructing tuples of type `T` from a key +/// of type `K`, a left tuple of type `L`, and a right tuple of type `R`. +type Mapper = dyn FnMut(&K, &L, &R) -> T; + +/// Represents the join of its `left` and `right` sub-expressions. /// /// **Example**: /// ```rust @@ -48,7 +52,7 @@ where right: Right, left_key: Rc K>>, right_key: Rc K>>, - mapper: Rc T>>, + mapper: Rc>>, relation_deps: Vec, view_deps: Vec, } @@ -65,7 +69,7 @@ where /// Creates a new `Join` expression over `left` and `right` where `left_key` /// and `right_key` are closures that return the join key for tuples of /// `left` and `right` respectively. The closure `mapper` computes the tuples - /// of the resulting expression from the join keys and the tuples of `left` and + /// of the resulting expression from the join key and the tuples of `left` and /// `right`. pub fn new( left: IL, @@ -88,8 +92,8 @@ where let (relation_deps, view_deps) = deps.into_dependencies(); Self { - left: left.clone(), - right: right.clone(), + left, + right, left_key: Rc::new(RefCell::new(left_key)), right_key: Rc::new(RefCell::new(right_key)), mapper: Rc::new(RefCell::new(mapper)), @@ -98,27 +102,27 @@ where } } - /// Returns a reference to the expression on left. + /// Returns a reference to the left sub-expression. #[inline(always)] pub fn left(&self) -> &Left { &self.left } - /// Returns a reference to the expression on right. + /// Returns a reference to the right sub-expression. #[inline(always)] pub fn right(&self) -> &Right { &self.right } /// Returns a mutable reference (of type `RefMut`) of the key closure for - /// the left expression. + /// the left sub-expression. #[inline(always)] pub(crate) fn left_key_mut(&self) -> RefMut K> { self.left_key.borrow_mut() } /// Returns a mutable reference (of type `RefMut`) of the key closure for - /// the right expression. + /// the right sub-expression. #[inline(always)] pub(crate) fn right_key_mut(&self) -> RefMut K> { self.right_key.borrow_mut() @@ -130,13 +134,13 @@ where self.mapper.borrow_mut() } - /// Returns a reference to relation dependencies of the receiver. + /// Returns a reference to the relation dependencies of the receiver. #[inline(always)] pub(crate) fn relation_deps(&self) -> &[String] { &self.relation_deps } - /// Returns a reference to view dependencies of the receiver. + /// Returns a reference to the view dependencies of the receiver. #[inline(always)] pub(crate) fn view_deps(&self) -> &[ViewRef] { &self.view_deps diff --git a/core/src/expression/mono.rs b/core/src/expression/mono.rs index f35503a..ada6ba2 100644 --- a/core/src/expression/mono.rs +++ b/core/src/expression/mono.rs @@ -12,6 +12,7 @@ use super::*; /// [`Tuple`]: ../trait.Tuple.html /// [expression]: ./trait.Expression.html #[derive(Clone, Debug)] +#[allow(clippy::type_complexity)] pub enum Mono where T: Tuple + 'static, @@ -20,14 +21,14 @@ where Empty(Empty), Singleton(Singleton), Relation(Relation), - Select(Select>>), - Project(Project>>), - Union(Union>, Box>>), - Intersect(Intersect>, Box>>), - Difference(Difference>, Box>>), - Product(Product>, Box>, T>), - Join(Join>, Box>, T>), - View(View>>), + Select(Box>>), + Project(Box>>), + Union(Box, Mono>>), + Intersect(Box, Mono>>), + Difference(Box, Mono>>), + Product(Box, Mono, T>>), + Join(Box, Mono, T>>), + View(Box>>), } impl Mono { @@ -61,51 +62,51 @@ impl From> for Mono { } } -impl From>>> for Mono { - fn from(select: Select>>) -> Self { - Self::Select(select) +impl From>> for Mono { + fn from(select: Select>) -> Self { + Self::Select(Box::new(select)) } } -impl From>>> for Mono { - fn from(project: Project>>) -> Self { - Self::Project(project) +impl From>> for Mono { + fn from(project: Project>) -> Self { + Self::Project(Box::new(project)) } } -impl From>, Box>>> for Mono { - fn from(union: Union>, Box>>) -> Self { - Self::Union(union) +impl From, Mono>> for Mono { + fn from(union: Union, Mono>) -> Self { + Self::Union(Box::new(union)) } } -impl From>, Box>>> for Mono { - fn from(intersect: Intersect>, Box>>) -> Self { - Self::Intersect(intersect) +impl From, Mono>> for Mono { + fn from(intersect: Intersect, Mono>) -> Self { + Self::Intersect(Box::new(intersect)) } } -impl From>, Box>>> for Mono { - fn from(difference: Difference>, Box>>) -> Self { - Self::Difference(difference) +impl From, Mono>> for Mono { + fn from(difference: Difference, Mono>) -> Self { + Self::Difference(Box::new(difference)) } } -impl From>, Box>, T>> for Mono { - fn from(product: Product>, Box>, T>) -> Self { - Self::Product(product) +impl From, Mono, T>> for Mono { + fn from(product: Product, Mono, T>) -> Self { + Self::Product(Box::new(product)) } } -impl From>, Box>, T>> for Mono { - fn from(join: Join>, Box>, T>) -> Self { - Self::Join(join) +impl From, Mono, T>> for Mono { + fn from(join: Join, Mono, T>) -> Self { + Self::Join(Box::new(join)) } } -impl From>>> for Mono { - fn from(view: View>>) -> Self { - Self::View(view) +impl From>> for Mono { + fn from(view: View>) -> Self { + Self::View(Box::new(view)) } } diff --git a/core/src/expression/product.rs b/core/src/expression/product.rs index 866682a..f94c780 100644 --- a/core/src/expression/product.rs +++ b/core/src/expression/product.rs @@ -64,39 +64,39 @@ where let (relation_deps, view_deps) = deps.into_dependencies(); Self { - left: left.clone(), - right: right.clone(), + left, + right, mapper: Rc::new(RefCell::new(project)), relation_deps: relation_deps.into_iter().collect(), view_deps: view_deps.into_iter().collect(), } } - /// Returns a reference to the expression on left. + /// Returns a reference to the left sub-expression. #[inline(always)] - pub(crate) fn left(&self) -> &Left { + pub fn left(&self) -> &Left { &self.left } - /// Returns a reference to the expression on right. + /// Returns a reference to the right sub-expression. #[inline(always)] - pub(crate) fn right(&self) -> &Right { + pub fn right(&self) -> &Right { &self.right } /// Returns a mutable reference (of type `std::cell::RefMut`) to the mapping closure. #[inline(always)] - pub(crate) fn mapper_mut(&self) -> RefMut T> { + pub fn mapper_mut(&self) -> RefMut T> { self.mapper.borrow_mut() } - /// Returns a reference to relation dependencies of the receiver. + /// Returns a reference to the relation dependencies of the receiver. #[inline(always)] pub(crate) fn relation_deps(&self) -> &[String] { &self.relation_deps } - /// Returns a reference to view dependencies of the receiver. + /// Returns a reference to the view dependencies of the receiver. #[inline(always)] pub(crate) fn view_deps(&self) -> &[ViewRef] { &self.view_deps diff --git a/core/src/expression/project.rs b/core/src/expression/project.rs index a127701..d73fa4a 100644 --- a/core/src/expression/project.rs +++ b/core/src/expression/project.rs @@ -6,7 +6,7 @@ use std::{ rc::Rc, }; -/// Projects the inner expression of type `S` to an expression of type `T`. +/// Projects the tuples of an inner sub-expression of type `S` to tuples of type `T`. /// /// **Example**: /// ```rust @@ -57,14 +57,14 @@ where let (relation_deps, view_deps) = deps.into_dependencies(); Self { - expression: expression.clone(), + expression, mapper: Rc::new(RefCell::new(mapper)), relation_deps: relation_deps.into_iter().collect(), view_deps: view_deps.into_iter().collect(), } } - /// Returns a reference to the underlying expression. + /// Returns a reference to the underlying sub-expression. #[inline(always)] pub fn expression(&self) -> &E { &self.expression @@ -76,13 +76,13 @@ where self.mapper.borrow_mut() } - /// Returns a reference to relation dependencies of the receiver. + /// Returns a reference to the relation dependencies of the receiver. #[inline(always)] pub(crate) fn relation_deps(&self) -> &[String] { &self.relation_deps } - /// Returns a reference to view dependencies of the receiver. + /// Returns a reference to the view dependencies of the receiver. #[inline(always)] pub(crate) fn view_deps(&self) -> &[ViewRef] { &self.view_deps diff --git a/core/src/expression/relation.rs b/core/src/expression/relation.rs index b29d632..18d57de 100644 --- a/core/src/expression/relation.rs +++ b/core/src/expression/relation.rs @@ -2,8 +2,8 @@ use super::{Expression, Visitor}; use crate::Tuple; use std::marker::PhantomData; -/// Is an expression that points to a relation with tuples of type `T` that identified -/// by a relation `name`. +/// Is an expression corresponding to a relation with tuples of type `T` that is identified +/// by a `name`. /// /// **Example**: /// ```rust @@ -43,13 +43,13 @@ where } } - /// Returns the name of this relation. + /// Returns a reference to the name by which the relation is identified. #[inline(always)] pub fn name(&self) -> &str { &self.name } - /// Returns a reference to relation dependencies of the receiver. + /// Returns a reference to the relation dependencies of the receiver. #[inline(always)] pub(crate) fn relation_deps(&self) -> &[String] { &self.relation_deps diff --git a/core/src/expression/select.rs b/core/src/expression/select.rs index 90c5f8e..089a98b 100644 --- a/core/src/expression/select.rs +++ b/core/src/expression/select.rs @@ -6,7 +6,7 @@ use std::{ rc::Rc, }; -/// Selects tuples of the underlying expression according to a given predicate. +/// Selects tuples of the underlying sub-expression according to a given predicate. /// /// **Example**: /// ```rust @@ -62,7 +62,7 @@ where } } - /// Returns a reference to the underlying expression. + /// Returns a reference to the underlying sub-expression. #[inline(always)] pub fn expression(&self) -> &E { &self.expression @@ -74,13 +74,13 @@ where self.predicate.borrow_mut() } - /// Returns a reference to relation dependencies of the receiver. + /// Returns a reference to the relation dependencies of the receiver. #[inline(always)] pub(crate) fn relation_deps(&self) -> &[String] { &self.relation_deps } - /// Returns a reference to view dependencies of the receiver. + /// Returns a reference to the view dependencies of the receiver. #[inline(always)] pub(crate) fn view_deps(&self) -> &[ViewRef] { &self.view_deps diff --git a/core/src/expression/singleton.rs b/core/src/expression/singleton.rs index 92abfb0..40054a7 100644 --- a/core/src/expression/singleton.rs +++ b/core/src/expression/singleton.rs @@ -18,12 +18,12 @@ where T: Tuple; impl Singleton { - /// Create a new instance of `Singleton` with `tuple` as its inner value. + /// Create a new instance of `Singleton` with `tuple` as the inner value. pub fn new(tuple: T) -> Self { Self(tuple) } - /// Returns the inner value of the receiver. + /// Returns a reference to the inner value of the receiver. #[inline(always)] pub fn tuple(&self) -> &T { &self.0 diff --git a/core/src/expression/union.rs b/core/src/expression/union.rs index d621512..d3c0744 100644 --- a/core/src/expression/union.rs +++ b/core/src/expression/union.rs @@ -2,7 +2,7 @@ use super::{view::ViewRef, Expression, IntoExpression, Visitor}; use crate::Tuple; use std::marker::PhantomData; -/// Evaluates to the union of the tuples in `left` and `right` expressions. +/// Evaluates to the union of the tuples in its `left` and `right` sub-expressions. /// /// **Example**: /// ```rust @@ -39,7 +39,7 @@ where L: Expression, R: Expression, { - /// Creates a new instance of `Union` for `left ∪ right`. + /// Creates a new instance of `Union` corresponding to `left ∪ right`. pub fn new(left: IL, right: IR) -> Self where IL: IntoExpression, @@ -55,33 +55,33 @@ where let (relation_deps, view_deps) = deps.into_dependencies(); Self { - left: left.clone(), - right: right.clone(), + left, + right, relation_deps: relation_deps.into_iter().collect(), view_deps: view_deps.into_iter().collect(), _marker: PhantomData, } } - /// Returns a reference to the expression on left. + /// Returns a reference to the left sub-expression. #[inline(always)] pub fn left(&self) -> &L { &self.left } - /// Returns a reference to the expression on right. + /// Returns a reference to the right sub-expression. #[inline(always)] pub fn right(&self) -> &R { &self.right } - /// Returns a reference to relation dependencies of the receiver. + /// Returns a reference to the relation dependencies of the receiver. #[inline(always)] pub(crate) fn relation_deps(&self) -> &[String] { &self.relation_deps } - /// Returns a reference to view dependencies of the receiver. + /// Returns a reference to the view dependencies of the receiver. #[inline(always)] pub(crate) fn view_deps(&self) -> &[ViewRef] { &self.view_deps diff --git a/core/src/expression/view.rs b/core/src/expression/view.rs index cbdf46f..0e5ad04 100644 --- a/core/src/expression/view.rs +++ b/core/src/expression/view.rs @@ -69,13 +69,13 @@ where } } - /// Returns the reference of this view. + /// Returns the reference to this view. #[inline(always)] pub(crate) fn reference(&self) -> &ViewRef { &self.reference } - /// Returns a reference to view dependencies of the receiver. + /// Returns a reference to the view dependencies of the receiver. #[inline(always)] pub(crate) fn view_deps(&self) -> &[ViewRef] { &self.view_deps diff --git a/core/src/lib.rs b/core/src/lib.rs index babdc87..0fc3f61 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,5 +1,4 @@ -/*! Implements a minimal [database] and relational [expressions] for evaluating queries -in the database. +/*! Implements a minimal [database] and relational algebraic [expressions] for evaluating queries in the database. [database]: ./struct.Database.html [expressions]: ./expression/index.html @@ -14,7 +13,9 @@ pub use database::{Database, Tuples}; pub use expression::Expression; use thiserror::Error; -/// Is the trait of tuples (analogous to the rows of a relational table). +/// Is the trait of tuples. Tuples are the smallest unit of data stored in databases. +/// +/// **Note**: Tuples are analogous to the rows of a table in a conventional database. pub trait Tuple: Ord + Clone + std::fmt::Debug {} impl Tuple for T {}