diff options
author | Devon Sawatsky <novedevo@gmail.com> | 2023-10-21 23:40:44 -0700 |
---|---|---|
committer | Devon Sawatsky <novedevo@gmail.com> | 2023-10-21 23:40:44 -0700 |
commit | 2628856cf6e1b0d9c2e2ac87d1ae9d3ff716a47f (patch) | |
tree | 37b7dccda799e8f54a5948790c9412f9e25f3b89 | |
parent | 192a75b569b05f755bfa77551a0084f0cd87b604 (diff) | |
download | gifed-2628856cf6e1b0d9c2e2ac87d1ae9d3ff716a47f.tar.gz gifed-2628856cf6e1b0d9c2e2ac87d1ae9d3ff716a47f.zip |
stop pushing and popping the buffer, just get slices
-rw-r--r-- | gifed/src/lzw.rs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/gifed/src/lzw.rs b/gifed/src/lzw.rs index 65ebb06..bbf1d8c 100644 --- a/gifed/src/lzw.rs +++ b/gifed/src/lzw.rs @@ -28,14 +28,11 @@ impl LZW { buffer.push(index); if !dictionary.contains_key(&buffer) { - buffer.pop(); - - if let Some(&code) = dictionary.get(&buffer) { + if let Some(&code) = dictionary.get(&buffer[..buffer.len() - 1]) { out.push_bits(code_size, code); - // Put the code back and add the vec to the dict - buffer.push(indicie); - dictionary.insert(buffer.clone(), next_code); + // add the vec to the dict + dictionary.insert(buffer, next_code); next_code += 1; // If the next_code can't fit in the code_size, we have to increase it @@ -43,10 +40,9 @@ impl LZW { code_size += 1; } - buffer.clear(); - buffer.push(indicie); + buffer = vec![index]; } else { - println!("indicie is: {}", indicie); + println!("index is: {index}"); println!("buffer is: {:?}", buffer); println!("dictionary: {:?}", dictionary); unreachable!() |