-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
68 additions
and
28 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
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
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
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
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
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,41 @@ | ||
use std::collections::HashMap; | ||
|
||
#[derive(Debug, Clone)] | ||
pub(crate) struct InternalMapper { | ||
pub(crate) forward: HashMap<u16, u16>, | ||
pub(crate) backward: Vec<u16> | ||
} | ||
|
||
impl InternalMapper { | ||
pub fn new() -> Self { | ||
Self { | ||
forward: HashMap::new(), | ||
backward: Vec::new() | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub(crate) enum MapperVariant { | ||
IdentityMapper, | ||
HashmapMapper(InternalMapper) | ||
} | ||
|
||
/// A mapper that maps old gids to new ones. | ||
#[derive(Debug, Clone)] | ||
pub struct Mapper(pub(crate) MapperVariant); | ||
|
||
impl Mapper { | ||
/// Create a mapper that maps each gid to itself. | ||
pub fn identity_mapper() -> Self { | ||
Self(MapperVariant::IdentityMapper) | ||
} | ||
|
||
/// Get the newly mapped gid for an old gid. | ||
pub fn get(&self, gid: u16) -> Option<u16> { | ||
match self.0 { | ||
MapperVariant::IdentityMapper => Some(gid), | ||
MapperVariant::HashmapMapper(ref h) => h.forward.get(&gid).copied() | ||
} | ||
} | ||
} |
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
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