Changeset - 6f7aa78a47f7
[Not reviewed]
default
0 1 0
Laman - 10 months ago 2024-06-11 22:33:48

added a proper START constant
1 file changed with 6 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/main.rs
Show inline comments
 
use std::collections::{HashMap, HashSet};
 

	
 
const START: usize = usize::MAX;
 

	
 
trait Token {
 
	fn is_skippable(&self) -> bool {false}
 
	fn list_first(&self) -> Vec<usize>;
 
@@ -130,8 +132,8 @@ fn parse(pattern: &String, offset: usize
 
				i = j+1;
 
			}
 
			'*' => {
 
				let segment = res.pop().unwrap();
 
				res.push(Box::new(Asterisk{content: segment}));
 
				let token = res.pop().unwrap();
 
				res.push(Box::new(Asterisk{content: token}));
 
				i += 1;
 
			}
 
			c => {
 
@@ -157,7 +159,7 @@ impl Regexp {
 
		
 
		for i in r.list_first() {
 
			let c = pattern_chars[i];
 
			let key = (99, c);
 
			let key = (START, c);
 
			match rules.get_mut(&key) {
 
				Some(set) => {set.insert(i);},
 
				None => {rules.insert(key, HashSet::from([i]));}
 
@@ -179,7 +181,7 @@ impl Regexp {
 
	}
 

	
 
	pub fn eval(&self, s: String) -> bool {
 
		let mut multistate = HashSet::from([99]);
 
		let mut multistate = HashSet::from([START]);
 

	
 
		for c in s.chars() {
 
			let mut new_multistate = HashSet::new();
0 comments (0 inline, 0 general)