Use HashSet for cells and in Plugin public API

This commit is contained in:
Tyler Hallada 2022-09-30 16:43:19 -04:00
parent 22c5744cd5
commit e79480794f

View File

@ -25,9 +25,9 @@ pub struct Plugin<'a> {
/// Parsed [TES4 header record](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/TES4) with metadata about the plugin /// Parsed [TES4 header record](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/TES4) with metadata about the plugin
pub header: PluginHeader<'a>, pub header: PluginHeader<'a>,
/// Parsed [WRLD records](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/WRLD) contained in the plugin /// Parsed [WRLD records](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/WRLD) contained in the plugin
pub worlds: Vec<World>, pub worlds: HashSet<World>,
/// Parsed [CELL records](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/CELL) contained in the plugin /// Parsed [CELL records](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/CELL) contained in the plugin
pub cells: Vec<Cell>, pub cells: HashSet<Cell>,
} }
/// Parsed [TES4 header record](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/TES4) /// Parsed [TES4 header record](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/TES4)
@ -42,7 +42,7 @@ pub struct PluginHeader<'a> {
} }
/// Parsed [CELL records](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/CELL) /// Parsed [CELL records](https://en.uesp.net/wiki/Skyrim_Mod:Mod_File_Format/CELL)
#[derive(Debug, Clone, PartialEq, Serialize)] #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
pub struct Cell { pub struct Cell {
pub form_id: u32, pub form_id: u32,
pub editor_id: Option<String>, pub editor_id: Option<String>,
@ -223,7 +223,7 @@ pub fn parse_plugin(input: &[u8]) -> Result<Plugin> {
.map_err(|_err| anyhow!("Failed to parse plugin header and find CELL data"))?; .map_err(|_err| anyhow!("Failed to parse plugin header and find CELL data"))?;
let decompressed_cells = decompress_cells(unparsed_cells)?; let decompressed_cells = decompress_cells(unparsed_cells)?;
let mut cells = Vec::new(); let mut cells = HashSet::new();
for decompressed_cell in decompressed_cells { for decompressed_cell in decompressed_cells {
let (_, cell) = parse_cell( let (_, cell) = parse_cell(
&decompressed_cell.data, &decompressed_cell.data,
@ -232,12 +232,12 @@ pub fn parse_plugin(input: &[u8]) -> Result<Plugin> {
decompressed_cell.world_form_id, decompressed_cell.world_form_id,
) )
.unwrap(); .unwrap();
cells.push(cell); cells.insert(cell);
} }
Ok(Plugin { Ok(Plugin {
header, header,
worlds: Vec::from_iter(worlds), worlds,
cells, cells,
}) })
} }