MCPcopy Create free account
hub / github.com/davisking/dlib / shift_buffer

Method shift_buffer

dlib/lz77_buffer/lz77_buffer_kernel_2.h:288–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

286 typename sliding_buffer
287 >
288 void lz77_buffer_kernel_2<sliding_buffer>::
289 shift_buffer (
290 unsigned long N
291 )
292 {
293 unsigned long old_history_size = history_size;
294 unsigned long temp = history_size+N;
295 unsigned long new_nodes; // the number of nodes to pull from the nodes array
296 unsigned long recycled_nodes; // the number of nodes to pull from hash_table
297 lookahead_size -= N;
298 if (temp <= history_limit)
299 {
300 if (history_size <= 3)
301 {
302 if ((3-history_size) >= N)
303 new_nodes = 0;
304 else
305 new_nodes = N - (3-history_size);
306 }
307 else
308 {
309 new_nodes = N;
310 }
311
312 recycled_nodes = 0;
313 history_size = temp;
314 }
315 else
316 {
317 if (history_size != history_limit)
318 {
319 new_nodes = history_limit - history_size;
320 recycled_nodes = temp - history_limit;
321 history_size = history_limit;
322 }
323 else
324 {
325 new_nodes = 0;
326 recycled_nodes = N;
327 }
328 }
329
330 unsigned long i = lookahead_limit + 2;
331
332 // if there are any "new" nodes to add to the hash table
333 if (new_nodes != 0)
334 {
335 unsigned long stop = i - new_nodes;
336 for (; i > stop; --i)
337 {
338 nodes[next_free_node].next = 0;
339 nodes[next_free_node].id = buffer.get_element_id(i);
340 id_table[nodes[next_free_node].id] = 0;
341
342 unsigned long new_hash = hash(buffer[i],buffer[i-1],buffer[i-2],buffer[i-3]);
343
344 if (hash_table[new_hash] != 0)
345 id_table[hash_table[new_hash]->id] = &nodes[next_free_node];

Callers

nothing calls this directly

Calls 3

get_element_idMethod · 0.80
rotate_leftMethod · 0.80
hashFunction · 0.50

Tested by

no test coverage detected