Change a RefCell in Vertex to Cell

pull/393/head
QuarticCat 2022-09-28 05:56:53 +07:00
parent 2c6972c1b2
commit 3b0edb43a1
No known key found for this signature in database
GPG Key ID: 441CE956DEADBEEF
2 changed files with 16 additions and 16 deletions

@ -44,8 +44,8 @@ fn shortest_vertex_path<'a, 'b>(
let (edge, next) = neighbour; let (edge, next) = neighbour;
let distance_to_next = distance + edge.cost(); let distance_to_next = distance + edge.cost();
let found_shorter_route = match &*next.predecessor.borrow() { let found_shorter_route = match next.predecessor.get() {
Some((prev_shortest, _)) => distance_to_next < *prev_shortest, Some((prev_shortest, _)) => distance_to_next < prev_shortest,
None => true, None => true,
}; };
@ -74,7 +74,7 @@ fn shortest_vertex_path<'a, 'b>(
let mut vertex_route: Vec<&'b Vertex<'a, 'b>> = vec![]; let mut vertex_route: Vec<&'b Vertex<'a, 'b>> = vec![];
while let Some((_, node)) = current { while let Some((_, node)) = current {
vertex_route.push(node); vertex_route.push(node);
current = *node.predecessor.borrow(); current = node.predecessor.get();
} }
vertex_route.reverse(); vertex_route.reverse();

@ -3,7 +3,7 @@
use bumpalo::Bump; use bumpalo::Bump;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use std::{ use std::{
cell::RefCell, cell::{Cell, RefCell},
cmp::min, cmp::min,
fmt, fmt,
hash::{Hash, Hasher}, hash::{Hash, Hasher},
@ -50,7 +50,7 @@ use Edge::*;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Vertex<'a, 'b> { pub struct Vertex<'a, 'b> {
pub neighbours: RefCell<Option<Vec<(Edge, &'b Vertex<'a, 'b>)>>>, pub neighbours: RefCell<Option<Vec<(Edge, &'b Vertex<'a, 'b>)>>>,
pub predecessor: RefCell<Option<(u64, &'b Vertex<'a, 'b>)>>, pub predecessor: Cell<Option<(u64, &'b Vertex<'a, 'b>)>>,
pub lhs_syntax: Option<&'a Syntax<'a>>, pub lhs_syntax: Option<&'a Syntax<'a>>,
pub rhs_syntax: Option<&'a Syntax<'a>>, pub rhs_syntax: Option<&'a Syntax<'a>>,
parents: Stack<EnteredDelimiter<'a>>, parents: Stack<EnteredDelimiter<'a>>,
@ -260,7 +260,7 @@ impl<'a, 'b> Vertex<'a, 'b> {
let parents = Stack::new(); let parents = Stack::new();
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax, lhs_syntax,
rhs_syntax, rhs_syntax,
parents, parents,
@ -444,7 +444,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: lhs_parent.next_sibling(), lhs_syntax: lhs_parent.next_sibling(),
rhs_syntax: rhs_parent.next_sibling(), rhs_syntax: rhs_parent.next_sibling(),
can_pop_either: can_pop_either_parent(&parents_next), can_pop_either: can_pop_either_parent(&parents_next),
@ -469,7 +469,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: lhs_parent.next_sibling(), lhs_syntax: lhs_parent.next_sibling(),
rhs_syntax: v.rhs_syntax, rhs_syntax: v.rhs_syntax,
can_pop_either: can_pop_either_parent(&parents_next), can_pop_either: can_pop_either_parent(&parents_next),
@ -494,7 +494,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: v.lhs_syntax, lhs_syntax: v.lhs_syntax,
rhs_syntax: rhs_parent.next_sibling(), rhs_syntax: rhs_parent.next_sibling(),
can_pop_either: can_pop_either_parent(&parents_next), can_pop_either: can_pop_either_parent(&parents_next),
@ -521,7 +521,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: lhs_syntax.next_sibling(), lhs_syntax: lhs_syntax.next_sibling(),
rhs_syntax: rhs_syntax.next_sibling(), rhs_syntax: rhs_syntax.next_sibling(),
parents: v.parents.clone(), parents: v.parents.clone(),
@ -567,7 +567,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: lhs_next, lhs_syntax: lhs_next,
rhs_syntax: rhs_next, rhs_syntax: rhs_next,
parents: parents_next, parents: parents_next,
@ -605,7 +605,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: lhs_syntax.next_sibling(), lhs_syntax: lhs_syntax.next_sibling(),
rhs_syntax: rhs_syntax.next_sibling(), rhs_syntax: rhs_syntax.next_sibling(),
parents: v.parents.clone(), parents: v.parents.clone(),
@ -635,7 +635,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: lhs_syntax.next_sibling(), lhs_syntax: lhs_syntax.next_sibling(),
rhs_syntax: v.rhs_syntax, rhs_syntax: v.rhs_syntax,
parents: v.parents.clone(), parents: v.parents.clone(),
@ -661,7 +661,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: lhs_next, lhs_syntax: lhs_next,
rhs_syntax: v.rhs_syntax, rhs_syntax: v.rhs_syntax,
parents: parents_next, parents: parents_next,
@ -689,7 +689,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: v.lhs_syntax, lhs_syntax: v.lhs_syntax,
rhs_syntax: rhs_syntax.next_sibling(), rhs_syntax: rhs_syntax.next_sibling(),
parents: v.parents.clone(), parents: v.parents.clone(),
@ -715,7 +715,7 @@ pub fn get_set_neighbours<'syn, 'b>(
allocate_if_new( allocate_if_new(
Vertex { Vertex {
neighbours: RefCell::new(None), neighbours: RefCell::new(None),
predecessor: RefCell::new(None), predecessor: Cell::new(None),
lhs_syntax: v.lhs_syntax, lhs_syntax: v.lhs_syntax,
rhs_syntax: rhs_next, rhs_syntax: rhs_next,
parents: parents_next, parents: parents_next,