pub struct InMemoryUnitGraph { /* private fields */ }Expand description
An implementation of UnitGraph describing the units and relationships as an adjacency list
stored in hash maps. All of it is stored in memory, as the memory benchmarks show that less than
20 MB of memory are used even when opening a large Trane library.
Trait Implementations§
Source§impl Clone for InMemoryUnitGraph
impl Clone for InMemoryUnitGraph
Source§fn clone(&self) -> InMemoryUnitGraph
fn clone(&self) -> InMemoryUnitGraph
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for InMemoryUnitGraph
impl Debug for InMemoryUnitGraph
Source§impl Default for InMemoryUnitGraph
impl Default for InMemoryUnitGraph
Source§fn default() -> InMemoryUnitGraph
fn default() -> InMemoryUnitGraph
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for InMemoryUnitGraph
impl<'de> Deserialize<'de> for InMemoryUnitGraph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for InMemoryUnitGraph
impl PartialEq for InMemoryUnitGraph
Source§impl Serialize for InMemoryUnitGraph
impl Serialize for InMemoryUnitGraph
Source§impl UnitGraph for InMemoryUnitGraph
impl UnitGraph for InMemoryUnitGraph
Source§fn add_course(&mut self, course_id: Ustr) -> Result<(), UnitGraphError>
fn add_course(&mut self, course_id: Ustr) -> Result<(), UnitGraphError>
Adds a new course to the unit graph.
Source§fn add_lesson(
&mut self,
lesson_id: Ustr,
course_id: Ustr,
) -> Result<(), UnitGraphError>
fn add_lesson( &mut self, lesson_id: Ustr, course_id: Ustr, ) -> Result<(), UnitGraphError>
Adds a new lesson to the unit graph. It also takes the ID of the course to which this lesson
belongs.
Source§fn add_exercise(
&mut self,
exercise_id: Ustr,
lesson_id: Ustr,
) -> Result<(), UnitGraphError>
fn add_exercise( &mut self, exercise_id: Ustr, lesson_id: Ustr, ) -> Result<(), UnitGraphError>
Adds a new exercise to the unit graph. It also takes the ID of the lesson to which this
exercise belongs.
Source§fn add_dependencies(
&mut self,
unit_id: Ustr,
unit_type: UnitType,
dependencies: &[Ustr],
) -> Result<(), UnitGraphError>
fn add_dependencies( &mut self, unit_id: Ustr, unit_type: UnitType, dependencies: &[Ustr], ) -> Result<(), UnitGraphError>
Takes a unit and its dependencies and updates the graph accordingly. Returns an error if
unit_type is UnitType::Exercise as only courses and lessons are allowed to have
dependencies. An error is also returned if the unit was not previously added by calling one
of add_course or add_lesson.Source§fn add_encompassed(
&mut self,
unit_id: Ustr,
dependencies: &[Ustr],
encompassed: &[(Ustr, f32)],
) -> Result<(), UnitGraphError>
fn add_encompassed( &mut self, unit_id: Ustr, dependencies: &[Ustr], encompassed: &[(Ustr, f32)], ) -> Result<(), UnitGraphError>
Adds the list of encompassed units for the given unit to the graph. Dependencies not in the
list of encompassed units are added with a default weight of 1.0. Returns an error if any
of the weights are not within the range [0.0, 1.0].
Source§fn set_encompasing_equals_dependency(&mut self)
fn set_encompasing_equals_dependency(&mut self)
Tells
UnitGraph that the encompassing and dependency graphs are the same. That is, no
manifest explicitly declared encompassed units. In this case, the encompassing graph is
identical to the dependency graph with all weights set to 1.0. The caller should use this
function after building the full graph to avoid the overhead of storing two identical
graphs.Source§fn encompasing_equals_dependency(&self) -> bool
fn encompasing_equals_dependency(&self) -> bool
Whether the encompassing and dependency graphs are effectively the same.
Source§fn add_superseded(&mut self, unit_id: Ustr, superseded: &[Ustr])
fn add_superseded(&mut self, unit_id: Ustr, superseded: &[Ustr])
Adds the list of superseded units for the given unit to the graph.
Source§fn get_unit_type(&self, unit_id: Ustr) -> Option<UnitType>
fn get_unit_type(&self, unit_id: Ustr) -> Option<UnitType>
Returns the type of the given unit.
Source§fn get_course_lessons(&self, course_id: Ustr) -> Option<UstrSet>
fn get_course_lessons(&self, course_id: Ustr) -> Option<UstrSet>
Returns the lessons belonging to the given course.
Source§fn get_starting_lessons(&self, course_id: Ustr) -> Option<UstrSet>
fn get_starting_lessons(&self, course_id: Ustr) -> Option<UstrSet>
Returns the starting lessons for the given course.
Source§fn update_starting_lessons(&mut self)
fn update_starting_lessons(&mut self)
Updates the starting lessons for all courses. The starting lessons of the course are those
of its lessons that should be practiced first when the course is introduced to the student.
The scheduler uses them to traverse through the other lessons in the course in the correct
order. This function should be called once after all the courses and lessons have been added
to the graph.
Source§fn get_lesson_course(&self, lesson_id: Ustr) -> Option<Ustr>
fn get_lesson_course(&self, lesson_id: Ustr) -> Option<Ustr>
Returns the course to which the given lesson belongs.
Source§fn get_lesson_exercises(&self, lesson_id: Ustr) -> Option<UstrSet>
fn get_lesson_exercises(&self, lesson_id: Ustr) -> Option<UstrSet>
Returns the exercises belonging to the given lesson.
Source§fn get_exercise_lesson(&self, exercise_id: Ustr) -> Option<Ustr>
fn get_exercise_lesson(&self, exercise_id: Ustr) -> Option<Ustr>
Returns the lesson to which the given exercise belongs.
Source§fn get_dependencies(&self, unit_id: Ustr) -> Option<UstrSet>
fn get_dependencies(&self, unit_id: Ustr) -> Option<UstrSet>
Returns the weights of the dependencies of the given unit.
Source§fn get_dependents(&self, unit_id: Ustr) -> Option<UstrSet>
fn get_dependents(&self, unit_id: Ustr) -> Option<UstrSet>
Returns all the units which depend on the given unit.
Source§fn get_dependency_sinks(&self) -> UstrSet
fn get_dependency_sinks(&self) -> UstrSet
Returns the dependency sinks of the graph. A dependency sink is a unit with no dependencies
from which a walk of the entire unit graph needs to start. Because the lessons in a course
implicitly depend on their course, properly initialized lessons do not belong to this set. Read more
Source§fn get_encompasses(&self, unit_id: Ustr) -> Option<Vec<(Ustr, f32)>>
fn get_encompasses(&self, unit_id: Ustr) -> Option<Vec<(Ustr, f32)>>
Returns the units that this unit encompasses.
Source§fn get_encompassed_by(&self, unit_id: Ustr) -> Option<Vec<(Ustr, f32)>>
fn get_encompassed_by(&self, unit_id: Ustr) -> Option<Vec<(Ustr, f32)>>
Returns the units that the given unit is encompassed by.
Source§fn get_supersedes(&self, unit_id: Ustr) -> Option<UstrSet>
fn get_supersedes(&self, unit_id: Ustr) -> Option<UstrSet>
Returns the units that this unit supersedes.
Source§fn get_superseded_by(&self, unit_id: Ustr) -> Option<UstrSet>
fn get_superseded_by(&self, unit_id: Ustr) -> Option<UstrSet>
Returns the units that the given unit is superseded by.
Source§fn check_cycles(&self) -> Result<(), UnitGraphError>
fn check_cycles(&self) -> Result<(), UnitGraphError>
Performs a cycle check on the graph, done currently when opening the Trane library to
prevent any infinite traversal of the graph and immediately inform the user of the issue.
impl StructuralPartialEq for InMemoryUnitGraph
Auto Trait Implementations§
impl Freeze for InMemoryUnitGraph
impl RefUnwindSafe for InMemoryUnitGraph
impl Send for InMemoryUnitGraph
impl Sync for InMemoryUnitGraph
impl Unpin for InMemoryUnitGraph
impl UnsafeUnpin for InMemoryUnitGraph
impl UnwindSafe for InMemoryUnitGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more