Skip to content

Commit

Permalink
Don't upsert duplicates
Browse files Browse the repository at this point in the history
This was fallout from adding `trim_explanation` in an earlier commit
5962f94. The simplistic logic treats each gloss as its possible own
headword, but we really don't want to include the same entry more than
once.

Fixes #33.
  • Loading branch information
eagleflo committed Jul 16, 2024
1 parent e4b5a6d commit 2f2c949
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{collections::HashMap, env, fs, io::Read, path::Path};

type Dictionary = HashMap<String, Vec<Entry>>;

#[derive(Clone, Serialize)]
#[derive(Clone, PartialEq, Serialize)]
pub struct Entry {
pub kanji: String,
pub reading: String,
Expand All @@ -15,7 +15,9 @@ pub struct Entry {

fn upsert(dictionary: &mut Dictionary, key: String, entry: &Entry) {
if let Some(entries) = dictionary.get_mut(&key) {
entries.push(entry.clone());
if !entries.contains(entry) {
entries.push(entry.clone());
}
} else {
dictionary.insert(key, vec![entry.clone()]);
}
Expand Down

0 comments on commit 2f2c949

Please sign in to comment.