MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / insert

Method insert

libCacheSim/dataStructure/splaytree.hpp:390–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

388
389template <typename K, typename V>
390void SplayTree<K, V>::insert(const K &key, const V &val)
391{
392 node *p = root_.get();
393 node *prev = nullptr;
394 while (p)
395 {
396 prev = p;
397 if (key == p->first)
398 {
399 p->second = val;
400 return;
401 }
402 else if (key < p->first)
403 p = p->left.get();
404 else if (key > p->first)
405 p = p->right.get();
406 }
407 node_ptr n(new node(key, val));
408
409 ++node_count_;
410 sum += val;
411
412 if (prev == nullptr)
413 {
414 root_ = move(n);
415 }
416 else if (key < prev->first)
417 {
418 prev->left = move(n);
419 prev->left->parent = prev;
420 splay(prev->left.get());
421 }
422 else
423 {
424 prev->right = move(n);
425 prev->right->parent = prev;
426 splay(prev->right.get());
427 }
428}
429
430template <typename K, typename V>
431typename SplayTree<K, V>::node *SplayTree<K, V>::find_(const K &key)

Callers 15

cache_get_baseFunction · 0.45
ARCv0_insertFunction · 0.45
ARCv0_get_debugFunction · 0.45
LeCaRv0_insertFunction · 0.45
S3FIFO_insertFunction · 0.45
S3FIFO_evict_smallFunction · 0.45
S3FIFO_evict_mainFunction · 0.45
S3FIFOd_insertFunction · 0.45
S3FIFOd_evictFunction · 0.45
QDLP_insertFunction · 0.45
LIRS_insertFunction · 0.45
hit_RD_HIRinQFunction · 0.45

Calls 2

splayFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected