Remove unnecessary allocations
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
agent::{self, Agent},
|
||||
@@ -267,17 +267,27 @@ impl History {
|
||||
"(length(weights) > 0) & (length(composition) != length(weights))"
|
||||
);
|
||||
|
||||
let mut unique = Vec::with_capacity(10);
|
||||
|
||||
let this_agent = composition
|
||||
.iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>();
|
||||
.filter(|idx| {
|
||||
if !unique.contains(idx) {
|
||||
unique.push(*idx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for agent in &this_agent {
|
||||
if !self.agents.contains_key(agent) {
|
||||
self.agents.insert(
|
||||
*agent,
|
||||
**agent,
|
||||
Agent {
|
||||
player: priors.get(agent).cloned().unwrap_or_else(|| {
|
||||
Player::new(
|
||||
@@ -473,8 +483,8 @@ mod tests {
|
||||
|
||||
let p = Game::new(
|
||||
h.batches[1].events[0].within_priors(false, false, &h.batches[1].skills, &h.agents),
|
||||
vec![0.0, 1.0],
|
||||
vec![],
|
||||
&vec![0.0, 1.0],
|
||||
&vec![vec![1.0], vec![1.0]],
|
||||
P_DRAW,
|
||||
)
|
||||
.posteriors();
|
||||
|
||||
Reference in New Issue
Block a user