-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update internal Quranize data structure (#29)
* update internal Quranize data structure * update visibilities * refactor * bump version
- Loading branch information
Showing
5 changed files
with
115 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "quranize" | ||
version = "0.10.2" | ||
version = "0.10.3" | ||
authors = ["Alfan Nur Fauzan <[email protected]>"] | ||
edition = "2021" | ||
description = "Encoding transliterations into Quran forms." | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
mod list; | ||
pub use list::List; | ||
mod node; | ||
pub(crate) use node::Node; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#[derive(Default)] | ||
pub(crate) struct Node<T> { | ||
pub(crate) element: T, | ||
next: Option<Box<List<Self>>>, | ||
} | ||
|
||
struct List<T> { | ||
head: T, | ||
tail: Option<Box<Self>>, | ||
} | ||
|
||
impl<T: PartialEq> Node<T> { | ||
pub(crate) fn get_mut_or_add(&mut self, element: T) -> &mut Self { | ||
let pos = self.iter().position(|n| n.element == element); | ||
match pos { | ||
Some(n) => self.iter_mut().nth(n).unwrap(), | ||
None => { | ||
self.next = Some(Box::new(List { | ||
head: Node { | ||
element, | ||
next: None, | ||
}, | ||
tail: self.next.take(), | ||
})); | ||
self.iter_mut().next().unwrap() | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn iter(&self) -> Iter<Self> { | ||
Iter { | ||
next: self.next.as_deref(), | ||
} | ||
} | ||
|
||
fn iter_mut(&mut self) -> IterMut<Self> { | ||
IterMut { | ||
next: self.next.as_deref_mut(), | ||
} | ||
} | ||
} | ||
|
||
pub(crate) struct Iter<'a, T> { | ||
next: Option<&'a List<T>>, | ||
} | ||
|
||
impl<'a, T> Iterator for Iter<'a, T> { | ||
type Item = &'a T; | ||
fn next(&mut self) -> Option<Self::Item> { | ||
self.next.map(|list| { | ||
self.next = list.tail.as_deref(); | ||
&list.head | ||
}) | ||
} | ||
} | ||
|
||
pub(crate) struct IterMut<'a, T> { | ||
next: Option<&'a mut List<T>>, | ||
} | ||
|
||
impl<'a, T> Iterator for IterMut<'a, T> { | ||
type Item = &'a mut T; | ||
fn next(&mut self) -> Option<Self::Item> { | ||
self.next.take().map(|list| { | ||
self.next = list.tail.as_deref_mut(); | ||
&mut list.head | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters