Skip to content

Commit

Permalink
switching two an ordered data structure to fix non-determinism problem
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Jun 16, 2022
1 parent 07956c3 commit d3240eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate simple_error;

use std::fs::File;
use std::io::{BufReader,BufRead};
use std::collections::{HashMap,HashSet,BTreeMap};
use std::collections::{HashMap,BTreeMap,BTreeSet};
use std::cmp::min;
use sesdiff::shortest_edit_script;
use std::time::SystemTime;
Expand Down Expand Up @@ -876,8 +876,8 @@ impl VariantModel {

/// Find the nearest anahashes that exists in the model (computing anahashes in the
/// neigbhourhood if needed).
pub(crate) fn find_nearest_anahashes<'a>(&'a self, focus: &AnaValue, max_distance: u8, stop_criterion: StopCriterion) -> HashSet<&'a AnaValue> {
let mut nearest: HashSet<&AnaValue> = HashSet::new();
pub(crate) fn find_nearest_anahashes<'a>(&'a self, focus: &AnaValue, max_distance: u8, stop_criterion: StopCriterion) -> BTreeSet<&'a AnaValue> {
let mut nearest: BTreeSet<&AnaValue> = BTreeSet::new();

let begintime = if self.debug >= 2 {
eprintln!("(finding nearest anagram matches for focus anavalue {}, max_distance={}, stop_criterion={:?})", focus, max_distance, stop_criterion);
Expand Down Expand Up @@ -1018,7 +1018,7 @@ impl VariantModel {


/// Gather instances with their edit distances and frequency, given a search string (normalised to the alphabet) and anagram hashes
pub(crate) fn gather_instances(&self, nearest_anagrams: &HashSet<&AnaValue>, querystring: &[u8], query: &str, max_edit_distance: u8) -> Vec<(VocabId,Distance)> {
pub(crate) fn gather_instances(&self, nearest_anagrams: &BTreeSet<&AnaValue>, querystring: &[u8], query: &str, max_edit_distance: u8) -> Vec<(VocabId,Distance)> {
let mut found_instances = Vec::new();
let mut pruned_instances = 0;

Expand Down
2 changes: 1 addition & 1 deletion tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ fn test0403_model_anagrams() {
#[test]
fn test0404_score_test() {
let (alphabet, _alphabet_size) = get_test_alphabet();
let mut model = VariantModel::new_with_alphabet(alphabet, Weights::default(), 1);
let mut model = VariantModel::new_with_alphabet(alphabet, Weights::default(), 4);
let lexicon: &[&str] = &["huis","huls"];
for text in lexicon.iter() {
model.add_to_vocabulary(text,None,&VocabParams::default());
Expand Down

0 comments on commit d3240eb

Please sign in to comment.