replace HashMap with IndexMap and HashSet with IndexSet
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "scryer-prolog"
|
||||
version = "0.8.91"
|
||||
version = "0.8.92"
|
||||
authors = ["Mark Thom <markjordanthom@gmail.com>"]
|
||||
repository = "https://github.com/mthom/scryer-prolog"
|
||||
description = "A modern Prolog implementation written mostly in Rust."
|
||||
|
||||
@@ -11,15 +11,16 @@ use prolog::iterators::*;
|
||||
use prolog::machine::machine_indices::*;
|
||||
use prolog::targets::*;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::{HashMap};
|
||||
use std::rc::Rc;
|
||||
use std::vec::Vec;
|
||||
|
||||
pub struct CodeGenerator<TermMarker> {
|
||||
flags: MachineFlags,
|
||||
marker: TermMarker,
|
||||
var_count: HashMap<Rc<Var>, usize>,
|
||||
var_count: IndexMap<Rc<Var>, usize>,
|
||||
non_counted_bt: bool
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker>
|
||||
{
|
||||
pub fn new(non_counted_bt: bool, flags: MachineFlags) -> Self {
|
||||
CodeGenerator { marker: Allocator::new(),
|
||||
var_count: HashMap::new(),
|
||||
var_count: IndexMap::new(),
|
||||
non_counted_bt,
|
||||
flags }
|
||||
}
|
||||
@@ -653,7 +654,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker>
|
||||
|
||||
fn mark_unsafe_fact_vars(&self, fact: &mut CompiledFact) -> UnsafeVarMarker
|
||||
{
|
||||
let mut unsafe_vars = HashMap::new();
|
||||
let mut unsafe_vars = IndexMap::new();
|
||||
|
||||
for var_status in self.marker.bindings().values() {
|
||||
unsafe_vars.insert(var_status.as_reg_type(), false);
|
||||
|
||||
@@ -9,7 +9,7 @@ use prolog::machine::machine_indices::*;
|
||||
use prolog::targets::*;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
use std::collections::BTreeSet;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct DebrayAllocator {
|
||||
@@ -17,7 +17,7 @@ pub struct DebrayAllocator {
|
||||
arg_c: usize,
|
||||
temp_lb: usize,
|
||||
arity: usize, // 0 if not at head.
|
||||
contents: HashMap<usize, Rc<Var>>,
|
||||
contents: IndexMap<usize, Rc<Var>>,
|
||||
in_use: BTreeSet<usize>,
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ impl<'a> Allocator<'a> for DebrayAllocator
|
||||
arg_c: 1,
|
||||
temp_lb: 1,
|
||||
bindings: IndexMap::new(),
|
||||
contents: HashMap::new(),
|
||||
contents: IndexMap::new(),
|
||||
in_use: BTreeSet::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ use prolog::forms::*;
|
||||
use prolog::instructions::*;
|
||||
use prolog::iterators::*;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::collections::btree_map::{IntoIter, IterMut, Values};
|
||||
use std::mem::swap;
|
||||
use std::rc::Rc;
|
||||
@@ -91,7 +93,7 @@ impl<'a> VariableFixtures<'a>
|
||||
pub fn populate_restricting_sets(&mut self)
|
||||
{
|
||||
// three stages:
|
||||
// 1. move the use sets of each variable to a local HashMap, use_set
|
||||
// 1. move the use sets of each variable to a local IndexMap, use_set
|
||||
// (iterate mutably, swap mutable refs).
|
||||
// 2. drain use_set. For each use set of U, add into the
|
||||
// no-use sets of appropriate variables T =/= U.
|
||||
@@ -99,7 +101,7 @@ impl<'a> VariableFixtures<'a>
|
||||
// Compute the conflict set of u.
|
||||
|
||||
// 1.
|
||||
let mut use_sets: HashMap<Rc<Var>, OccurrenceSet> = HashMap::new();
|
||||
let mut use_sets: IndexMap<Rc<Var>, OccurrenceSet> = IndexMap::new();
|
||||
|
||||
for (var, &mut (ref mut var_status, _)) in self.iter_mut() {
|
||||
if let &mut VarStatus::Temp(_, ref mut var_data) = var_status {
|
||||
@@ -110,7 +112,7 @@ impl<'a> VariableFixtures<'a>
|
||||
}
|
||||
}
|
||||
|
||||
for (u, use_set) in use_sets.drain() {
|
||||
for (u, use_set) in use_sets.drain(..) {
|
||||
// 2.
|
||||
for &(term_loc, reg) in use_set.iter() {
|
||||
if let GenContext::Last(cn_u) = term_loc {
|
||||
@@ -240,13 +242,13 @@ impl<'a> VariableFixtures<'a>
|
||||
}
|
||||
|
||||
pub struct UnsafeVarMarker {
|
||||
pub unsafe_vars: HashMap<RegType, bool>
|
||||
pub unsafe_vars: IndexMap<RegType, bool>
|
||||
}
|
||||
|
||||
impl UnsafeVarMarker {
|
||||
pub fn new() -> Self {
|
||||
UnsafeVarMarker {
|
||||
unsafe_vars: HashMap::new()
|
||||
unsafe_vars: IndexMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,10 @@ use prolog::machine::machine_indices::*;
|
||||
use prolog::ordered_float::OrderedFloat;
|
||||
use prolog::rug::{Integer, Rational};
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::collections::VecDeque;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub type PredicateKey = (ClauseName, usize); // name, arity.
|
||||
@@ -292,7 +294,7 @@ fn fetch_op_spec(name: ClauseName, arity: usize, spec: Option<SharedOpDesc>, op_
|
||||
})
|
||||
}
|
||||
|
||||
pub type ModuleDir = HashMap<ClauseName, Module>;
|
||||
pub type ModuleDir = IndexMap<ClauseName, Module>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ModuleDecl {
|
||||
|
||||
@@ -3,8 +3,9 @@ use prolog_parser::ast::*;
|
||||
use prolog::machine::machine_indices::*;
|
||||
use prolog::machine::machine_state::*;
|
||||
|
||||
use indexmap::IndexSet;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashSet;
|
||||
use std::ops::Deref;
|
||||
use std::vec::Vec;
|
||||
|
||||
@@ -187,13 +188,13 @@ impl<'a> MutStackHCIterator for HCPreOrderIterator<'a> {
|
||||
|
||||
pub struct HCAcyclicIterator<HCIter> {
|
||||
iter: HCIter,
|
||||
seen: HashSet<Addr>
|
||||
seen: IndexSet<Addr>
|
||||
}
|
||||
|
||||
impl<HCIter: MutStackHCIterator> HCAcyclicIterator<HCIter>
|
||||
{
|
||||
pub fn new(iter: HCIter) -> Self {
|
||||
HCAcyclicIterator { iter, seen: HashSet::new() }
|
||||
HCAcyclicIterator { iter, seen: IndexSet::new() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,14 +228,14 @@ impl<HCIter> Iterator for HCAcyclicIterator<HCIter>
|
||||
pub struct HCZippedAcyclicIterator<HCIter> {
|
||||
i1: HCIter,
|
||||
i2: HCIter,
|
||||
seen: HashSet<(Addr, Addr)>,
|
||||
seen: IndexSet<(Addr, Addr)>,
|
||||
pub first_to_expire: Ordering
|
||||
}
|
||||
|
||||
impl<HCIter: MutStackHCIterator> HCZippedAcyclicIterator<HCIter>
|
||||
{
|
||||
pub fn new(i1: HCIter, i2: HCIter) -> Self {
|
||||
HCZippedAcyclicIterator { i1, i2, seen: HashSet::new(),
|
||||
HCZippedAcyclicIterator { i1, i2, seen: IndexSet::new(),
|
||||
first_to_expire: Ordering::Equal }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@ use prolog::machine::machine_state::*;
|
||||
use prolog::ordered_float::OrderedFloat;
|
||||
use prolog::rug::{Integer};
|
||||
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::iter::once;
|
||||
use std::ops::{Range, RangeFrom};
|
||||
use std::rc::Rc;
|
||||
@@ -294,7 +295,7 @@ impl MachineState {
|
||||
}
|
||||
}
|
||||
|
||||
type ReverseHeapVarDict = HashMap<Addr, Rc<Var>>;
|
||||
type ReverseHeapVarDict = IndexMap<Addr, Rc<Var>>;
|
||||
|
||||
pub struct HCPrinter<'a, Outputter> {
|
||||
outputter: Outputter,
|
||||
@@ -303,10 +304,10 @@ pub struct HCPrinter<'a, Outputter> {
|
||||
state_stack: Vec<TokenOrRedirect>,
|
||||
toplevel_spec: Option<DirectedOp>,
|
||||
heap_locs: ReverseHeapVarDict,
|
||||
printed_vars: HashSet<Addr>,
|
||||
printed_vars: IndexSet<Addr>,
|
||||
last_item_idx: usize,
|
||||
cyclic_terms: HashMap<Addr, usize>,
|
||||
pub(crate) var_names: HashMap<Addr, String>,
|
||||
cyclic_terms: IndexMap<Addr, usize>,
|
||||
pub(crate) var_names: IndexMap<Addr, String>,
|
||||
pub(crate) numbervars_offset: Integer,
|
||||
pub(crate) numbervars: bool,
|
||||
pub(crate) quoted: bool,
|
||||
@@ -415,14 +416,14 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
|
||||
state_stack: vec![],
|
||||
heap_locs: ReverseHeapVarDict::new(),
|
||||
toplevel_spec: None,
|
||||
printed_vars: HashSet::new(),
|
||||
printed_vars: IndexSet::new(),
|
||||
last_item_idx: 0,
|
||||
numbervars: false,
|
||||
numbervars_offset: Integer::from(0),
|
||||
quoted: false,
|
||||
ignore_ops: false,
|
||||
cyclic_terms: HashMap::new(),
|
||||
var_names: HashMap::new() }
|
||||
cyclic_terms: IndexMap::new(),
|
||||
var_names: IndexMap::new() }
|
||||
}
|
||||
|
||||
pub fn from_heap_locs(machine_st: &'a MachineState, op_dir: &'a OpDir, output: Outputter)
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use prolog_parser::ast::*;
|
||||
|
||||
use prolog::instructions::*;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::hash::Hash;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -11,18 +14,18 @@ enum IntIndex {
|
||||
|
||||
pub struct CodeOffsets {
|
||||
flags: MachineFlags,
|
||||
pub constants: HashMap<Constant, ThirdLevelIndex>,
|
||||
pub constants: IndexMap<Constant, ThirdLevelIndex>,
|
||||
pub lists: ThirdLevelIndex,
|
||||
pub structures: HashMap<(ClauseName, usize), ThirdLevelIndex>
|
||||
pub structures: IndexMap<(ClauseName, usize), ThirdLevelIndex>
|
||||
}
|
||||
|
||||
impl CodeOffsets {
|
||||
pub fn new(flags: MachineFlags) -> Self {
|
||||
CodeOffsets {
|
||||
flags,
|
||||
constants: HashMap::new(),
|
||||
constants: IndexMap::new(),
|
||||
lists: Vec::new(),
|
||||
structures: HashMap::new()
|
||||
structures: IndexMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,11 +82,11 @@ impl CodeOffsets {
|
||||
};
|
||||
}
|
||||
|
||||
fn second_level_index<Index>(indices: HashMap<Index, ThirdLevelIndex>, prelude: &mut CodeDeque)
|
||||
-> HashMap<Index, IntIndex>
|
||||
fn second_level_index<Index>(indices: IndexMap<Index, ThirdLevelIndex>, prelude: &mut CodeDeque)
|
||||
-> IndexMap<Index, IntIndex>
|
||||
where Index: Eq + Hash
|
||||
{
|
||||
let mut index_locs = HashMap::new();
|
||||
let mut index_locs = IndexMap::new();
|
||||
|
||||
for (key, mut code) in indices.into_iter() {
|
||||
if code.len() > 1 {
|
||||
@@ -108,11 +111,11 @@ impl CodeOffsets {
|
||||
no_constants && no_structures && no_lists
|
||||
}
|
||||
|
||||
fn flatten_index<Index>(index: HashMap<Index, IntIndex>, len: usize)
|
||||
-> HashMap<Index, usize>
|
||||
fn flatten_index<Index>(index: IndexMap<Index, IntIndex>, len: usize)
|
||||
-> IndexMap<Index, usize>
|
||||
where Index: Eq + Hash
|
||||
{
|
||||
let mut flattened_index = HashMap::new();
|
||||
let mut flattened_index = IndexMap::new();
|
||||
|
||||
for (key, int_index) in index.into_iter() {
|
||||
match int_index {
|
||||
@@ -138,7 +141,7 @@ impl CodeOffsets {
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_on_constant(con_ind: HashMap<Constant, ThirdLevelIndex>, prelude: &mut CodeDeque)
|
||||
fn switch_on_constant(con_ind: IndexMap<Constant, ThirdLevelIndex>, prelude: &mut CodeDeque)
|
||||
-> IntIndex
|
||||
{
|
||||
let con_ind = Self::second_level_index(con_ind, prelude);
|
||||
@@ -157,7 +160,7 @@ impl CodeOffsets {
|
||||
}
|
||||
}
|
||||
|
||||
fn switch_on_structure(str_ind: HashMap<(ClauseName, usize), ThirdLevelIndex>,
|
||||
fn switch_on_structure(str_ind: IndexMap<(ClauseName, usize), ThirdLevelIndex>,
|
||||
prelude: &mut CodeDeque)
|
||||
-> IntIndex
|
||||
{
|
||||
|
||||
@@ -7,7 +7,9 @@ use prolog::machine::machine_indices::*;
|
||||
|
||||
use prolog::rug::Integer;
|
||||
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
fn reg_type_into_functor(r: RegType) -> MachineStub {
|
||||
match r {
|
||||
@@ -361,8 +363,8 @@ impl ControlInstruction {
|
||||
|
||||
pub enum IndexingInstruction {
|
||||
SwitchOnTerm(usize, usize, usize, usize),
|
||||
SwitchOnConstant(usize, HashMap<Constant, usize>),
|
||||
SwitchOnStructure(usize, HashMap<(ClauseName, usize), usize>)
|
||||
SwitchOnConstant(usize, IndexMap<Constant, usize>),
|
||||
SwitchOnStructure(usize, IndexMap<(ClauseName, usize), usize>)
|
||||
}
|
||||
|
||||
impl From<IndexingInstruction> for Line {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use prolog::machine::*;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use indexmap::IndexSet;
|
||||
|
||||
use std::vec::IntoIter;
|
||||
|
||||
pub static VERIFY_ATTRS: &str = include_str!("attributed_variables.pl");
|
||||
@@ -87,7 +88,7 @@ impl MachineState {
|
||||
|
||||
fn populate_project_attr_lists(&mut self) -> (Addr, Addr)
|
||||
{
|
||||
let mut query_vars = HashSet::new();
|
||||
let mut query_vars = IndexSet::new();
|
||||
let attr_vars = self.gather_attr_vars_created_since(0);
|
||||
|
||||
for (_, addr) in self.heap_locs.iter() {
|
||||
|
||||
@@ -12,8 +12,10 @@ use prolog::machine::machine_indices::*;
|
||||
use prolog::machine::term_expansion::{ExpansionAdditionResult};
|
||||
use prolog::machine::toplevel::*;
|
||||
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::collections::VecDeque;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::mem;
|
||||
@@ -325,13 +327,13 @@ pub struct GatherResult {
|
||||
pub struct ClauseCodeGenerator {
|
||||
len_offset: usize,
|
||||
code: Code,
|
||||
pi_to_loc: HashMap<PredicateKey, usize>
|
||||
pi_to_loc: IndexMap<PredicateKey, usize>
|
||||
}
|
||||
|
||||
impl ClauseCodeGenerator {
|
||||
#[inline]
|
||||
fn new(len_offset: usize) -> Self {
|
||||
ClauseCodeGenerator { len_offset, code: vec![], pi_to_loc: HashMap::new() }
|
||||
ClauseCodeGenerator { len_offset, code: vec![], pi_to_loc: IndexMap::new() }
|
||||
}
|
||||
|
||||
fn generate_clause_code(&mut self, dynamic_clause_map: DynamicClauseMap, wam: &Machine)
|
||||
@@ -375,7 +377,7 @@ impl ClauseCodeGenerator {
|
||||
}
|
||||
|
||||
pub struct ListingCompiler {
|
||||
non_counted_bt_preds: HashSet<PredicateKey>,
|
||||
non_counted_bt_preds: IndexSet<PredicateKey>,
|
||||
module: Option<Module>,
|
||||
user_term_dir: TermDir,
|
||||
orig_term_expansion_lens: (usize, usize),
|
||||
@@ -428,7 +430,7 @@ impl ListingCompiler {
|
||||
#[inline]
|
||||
pub fn new(code_repo: &CodeRepo) -> Self {
|
||||
ListingCompiler {
|
||||
non_counted_bt_preds: HashSet::new(),
|
||||
non_counted_bt_preds: IndexSet::new(),
|
||||
module: None,
|
||||
user_term_dir: TermDir::new(),
|
||||
orig_term_expansion_lens: code_repo.term_dir_entry_len((clause_name!("term_expansion"), 2)),
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use prolog_parser::ast::*;
|
||||
use prolog_parser::tabled_rc::*;
|
||||
|
||||
@@ -7,9 +5,11 @@ use prolog::clause_types::*;
|
||||
use prolog::fixtures::*;
|
||||
use prolog::forms::*;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::{BTreeMap, HashMap, VecDeque};
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::mem;
|
||||
use std::ops::{Add, AddAssign, Sub, SubAssign};
|
||||
use std::rc::Rc;
|
||||
@@ -427,11 +427,11 @@ impl Default for DynamicPredicateInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub type InSituCodeDir = HashMap<PredicateKey, usize>;
|
||||
pub type InSituCodeDir = IndexMap<PredicateKey, usize>;
|
||||
// key type: module name, predicate indicator.
|
||||
pub type DynamicCodeDir = HashMap<(ClauseName, ClauseName, usize), DynamicPredicateInfo>;
|
||||
pub type DynamicCodeDir = IndexMap<(ClauseName, ClauseName, usize), DynamicPredicateInfo>;
|
||||
|
||||
pub type GlobalVarDir = HashMap<ClauseName, Addr>;
|
||||
pub type GlobalVarDir = IndexMap<ClauseName, Addr>;
|
||||
|
||||
pub struct IndexStore {
|
||||
pub(super) atom_tbl: TabledData<Atom>,
|
||||
@@ -545,7 +545,7 @@ impl IndexStore {
|
||||
}
|
||||
|
||||
pub type CodeDir = BTreeMap<PredicateKey, CodeIndex>;
|
||||
pub type TermDir = HashMap<PredicateKey, (Predicate, VecDeque<TopLevel>)>;
|
||||
pub type TermDir = IndexMap<PredicateKey, (Predicate, VecDeque<TopLevel>)>;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
|
||||
pub enum CompileTimeHook {
|
||||
|
||||
@@ -21,8 +21,9 @@ use prolog::ordered_float::*;
|
||||
use prolog::rug::{Integer, Rational};
|
||||
use prolog::read::PrologStream;
|
||||
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
|
||||
use std::cmp::{min, max, Ordering};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::f64;
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
@@ -374,7 +375,7 @@ impl MachineState {
|
||||
|
||||
pub(super) fn unify_with_occurs_check(&mut self, a1: Addr, a2: Addr) {
|
||||
let mut pdl = vec![a1, a2];
|
||||
let mut tabu_list: HashSet<(Addr, Addr)> = HashSet::new();
|
||||
let mut tabu_list: IndexSet<(Addr, Addr)> = IndexSet::new();
|
||||
|
||||
self.fail = false;
|
||||
|
||||
@@ -479,7 +480,7 @@ impl MachineState {
|
||||
|
||||
pub(super) fn unify(&mut self, a1: Addr, a2: Addr) {
|
||||
let mut pdl = vec![a1, a2];
|
||||
let mut tabu_list: HashSet<(Addr, Addr)> = HashSet::new();
|
||||
let mut tabu_list: IndexSet<(Addr, Addr)> = IndexSet::new();
|
||||
|
||||
self.fail = false;
|
||||
|
||||
@@ -2071,7 +2072,7 @@ impl MachineState {
|
||||
}
|
||||
|
||||
pub(crate) fn is_cyclic_term(&self, addr: Addr) -> bool {
|
||||
let mut seen = HashSet::new();
|
||||
let mut seen = IndexSet::new();
|
||||
let mut fail = false;
|
||||
let mut iter = self.pre_order_iter(addr);
|
||||
|
||||
@@ -2835,7 +2836,7 @@ impl MachineState {
|
||||
let a1 = self[temp_v!(1)].clone();
|
||||
let a2 = self[temp_v!(2)].clone();
|
||||
|
||||
let mut var_pairs = HashMap::new();
|
||||
let mut var_pairs = IndexMap::new();
|
||||
|
||||
let iter = self.zipped_acyclic_pre_order_iter(a1, a2);
|
||||
|
||||
|
||||
@@ -37,7 +37,9 @@ use prolog::machine::modules::*;
|
||||
use prolog::machine::toplevel::stream_to_toplevel;
|
||||
use prolog::read::PrologStream;
|
||||
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::io::{Read, Write, stdout};
|
||||
use std::fs::File;
|
||||
use std::mem;
|
||||
|
||||
@@ -17,7 +17,9 @@ use prolog::ordered_float::OrderedFloat;
|
||||
use prolog::read::{PrologStream, readline};
|
||||
use prolog::rug::Integer;
|
||||
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::io::{stdout, Write};
|
||||
use std::iter::once;
|
||||
use std::mem;
|
||||
@@ -1672,7 +1674,7 @@ impl MachineState {
|
||||
&SystemClauseType::Succeed => {},
|
||||
&SystemClauseType::TermVariables => {
|
||||
let a1 = self[temp_v!(1)].clone();
|
||||
let mut seen_vars = HashSet::new();
|
||||
let mut seen_vars = IndexSet::new();
|
||||
|
||||
for item in self.acyclic_pre_order_iter(a1) {
|
||||
match item {
|
||||
@@ -1779,7 +1781,7 @@ impl MachineState {
|
||||
|
||||
match self.try_from_list(temp_v!(5), stub.clone()) {
|
||||
Ok(addrs) => {
|
||||
let mut var_names: HashMap<Addr, String> = HashMap::new();
|
||||
let mut var_names: IndexMap<Addr, String> = IndexMap::new();
|
||||
|
||||
for addr in addrs {
|
||||
match addr {
|
||||
|
||||
@@ -9,8 +9,10 @@ use prolog::machine::machine_indices::*;
|
||||
use prolog::machine::machine_state::MachineState;
|
||||
use prolog::machine::term_expansion::*;
|
||||
|
||||
use indexmap::{IndexMap, IndexSet};
|
||||
|
||||
use std::borrow::BorrowMut;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::collections::VecDeque;
|
||||
use std::cell::Cell;
|
||||
use std::io::Read;
|
||||
use std::mem;
|
||||
@@ -426,7 +428,7 @@ impl RelationWorker {
|
||||
|
||||
fn compute_head(&self, term: &Term) -> Vec<Term>
|
||||
{
|
||||
let mut vars = HashSet::new();
|
||||
let mut vars = IndexSet::new();
|
||||
|
||||
for term in post_order_iter(term) {
|
||||
if let TermRef::Var(_, _, v) = term {
|
||||
@@ -802,7 +804,7 @@ fn stream_to_toplevel<R: Read>(mut buffer: ParsingStream<R>, wam: &mut Machine)
|
||||
Ok(deque_to_packet(tl, queue))
|
||||
}
|
||||
|
||||
pub type DynamicClauseMap = HashMap<(ClauseName, usize), Vec<(Term, Term)>>;
|
||||
pub type DynamicClauseMap = IndexMap<(ClauseName, usize), Vec<(Term, Term)>>;
|
||||
|
||||
pub struct TopLevelBatchWorker<'a, R: Read> {
|
||||
pub(crate) term_stream: TermStream<'a, R>,
|
||||
@@ -823,7 +825,7 @@ impl<'a, R: Read> TopLevelBatchWorker<'a, R> {
|
||||
TopLevelBatchWorker { term_stream,
|
||||
rel_worker: RelationWorker::new(flags),
|
||||
results: vec![],
|
||||
dynamic_clause_map: HashMap::new(),
|
||||
dynamic_clause_map: IndexMap::new(),
|
||||
in_module: false }
|
||||
}
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ macro_rules! index_store {
|
||||
|
||||
macro_rules! default_index_store {
|
||||
($atom_tbl:expr) => (
|
||||
index_store!($atom_tbl, CodeDir::new(), default_op_dir(), HashMap::new())
|
||||
index_store!($atom_tbl, CodeDir::new(), default_op_dir(), IndexMap::new())
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
21
src/tests.rs
21
src/tests.rs
@@ -8,13 +8,14 @@ use prolog::machine::machine_indices::*;
|
||||
use prolog::machine::toplevel::*;
|
||||
use prolog::read::readline;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use indexmap::IndexSet;
|
||||
|
||||
use std::mem::swap;
|
||||
use std::ops::{Range, RangeFrom};
|
||||
|
||||
pub struct TestOutputter {
|
||||
results: Vec<HashSet<String>>,
|
||||
contents: HashSet<String>,
|
||||
results: Vec<IndexSet<String>>,
|
||||
contents: IndexSet<String>,
|
||||
focus: String
|
||||
}
|
||||
|
||||
@@ -22,7 +23,7 @@ impl TestOutputter {
|
||||
fn cache(&mut self) {
|
||||
self.begin_new_var();
|
||||
|
||||
let mut contents = HashSet::new();
|
||||
let mut contents = IndexSet::new();
|
||||
swap(&mut contents, &mut self.contents);
|
||||
|
||||
self.results.push(contents);
|
||||
@@ -30,11 +31,11 @@ impl TestOutputter {
|
||||
}
|
||||
|
||||
impl HCValueOutputter for TestOutputter {
|
||||
type Output = Vec<HashSet<String>>;
|
||||
type Output = Vec<IndexSet<String>>;
|
||||
|
||||
fn new() -> Self {
|
||||
TestOutputter { results: vec![],
|
||||
contents: HashSet::new(),
|
||||
contents: IndexSet::new(),
|
||||
focus: String::new() }
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ impl HCValueOutputter for TestOutputter {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect_test_output(wam: &mut Machine, alloc_locs: AllocVarDict) -> Vec<HashSet<String>>
|
||||
pub fn collect_test_output(wam: &mut Machine, alloc_locs: AllocVarDict) -> Vec<IndexSet<String>>
|
||||
{
|
||||
let mut output = TestOutputter::new();
|
||||
|
||||
@@ -100,7 +101,7 @@ pub fn collect_test_output(wam: &mut Machine, alloc_locs: AllocVarDict) -> Vec<H
|
||||
}
|
||||
|
||||
pub fn collect_test_output_with_limit(wam: &mut Machine, alloc_locs: AllocVarDict, limit: usize)
|
||||
-> Vec<HashSet<String>>
|
||||
-> Vec<IndexSet<String>>
|
||||
{
|
||||
let mut output = TestOutputter::new();
|
||||
|
||||
@@ -143,7 +144,7 @@ pub fn submit(wam: &mut Machine, buffer: &str) -> bool
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn submit_query(wam: &mut Machine, buffer: &str, result: Vec<HashSet<String>>) -> bool
|
||||
pub fn submit_query(wam: &mut Machine, buffer: &str, result: Vec<IndexSet<String>>) -> bool
|
||||
{
|
||||
wam.reset();
|
||||
|
||||
@@ -177,7 +178,7 @@ pub fn submit_query_without_results(wam: &mut Machine, buffer: &str) -> bool
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn submit_query_with_limit(wam: &mut Machine, buffer: &str,
|
||||
result: Vec<HashSet<String>>, limit: usize)
|
||||
result: Vec<IndexSet<String>>, limit: usize)
|
||||
-> bool
|
||||
{
|
||||
wam.reset();
|
||||
|
||||
Reference in New Issue
Block a user