MP6
Debugging Skills
|
A sorted Skip List class. More...
#include "skipList.h"
Public Member Functions | |
SkipList () | |
Default constructs the SkipList. More... | |
SkipList (int probability, int maxlevel) | |
Constructs an empty list with the specified probability and maxlevel. More... | |
SkipList (int key, HSLAPixel value) | |
Constructs the SkipList with one initial node, which is constructed with the provided values. More... | |
SkipList (int key, HSLAPixel value, int probability, int maxlevel) | |
Constructs the SkipList with one initial node, which is constructed with the provided values. More... | |
SkipList (const SkipList &other) | |
Copy constructs the current SkipList. More... | |
~SkipList () | |
The destructor for SkipList. More... | |
const SkipList & | operator= (const SkipList &other) |
The assignment= operator. More... | |
void | insert (int key, HSLAPixel value) |
Inserts a new node into the sorted order in the list, initialized with the provided values. More... | |
bool | remove (int key) |
Removes the node with the given key from the list. More... | |
PNG | makeImage (int imgSize, HSLAPixel fg, HSLAPixel bg) |
Makes and returns an image showing how degenerate the list is. More... | |
int | levelGenerator () |
Returns the height to use for the next node. More... | |
void | printKeys () |
A function that prints the keys of the list using only next pointers. More... | |
HSLAPixel | search (int key) |
A function that searches for the given key and returns the associated HSLAPixel Returns (0, 0, 0, 50) if it's not found. More... | |
void | printKeysReverse () |
A function that prints the keys in the list using only prev pointers. More... | |
vector< int > | traverse () |
A function that returns the keys of the list in a vector, using only next pointers. More... | |
vector< int > | traverseReverse () |
A function that returns the keys of the list in a vector, using only prev pointers. More... | |
PNG | toPNG (int maxHeight=100, HSLAPixel fg=HSLAPixel(0, 0, 0), HSLAPixel bg=HSLAPixel(0, 0, 1)) const |
A function that returns a PNG showing the structure of the current list NOTE: This draws the sentinel nodes as well. More... | |
Private Member Functions | |
SkipNode * | findR (int key) |
Finds the given key in the list if it exists, and returns a pointer to the node containing it. More... | |
SkipNode * | findRHelper (int key, int level, SkipNode *curr) |
Helper function for findR. More... | |
SkipNode * | findI (int key) |
An iterative find function. More... | |
SkipNode * | find (int key) |
Finds the given key in the list if it exists, and returns a pointer to the node containing it. More... | |
void | printKeysReverse (SkipNode *curr) |
A helper function for printKeysReverse(). More... | |
void | traverseReverse (SkipNode *curr, vector< int > &out) |
A helper function for traverseReverse() More... | |
void | clear () |
Clears up all memory associated with this SkipList. More... | |
void | copy (const SkipList &other) |
The copy() helper method - used in the copy constructor and assignment= operator. More... | |
SkipPointer | gdbGetPointer (SkipNode *node, size_t index) const |
A function that will return the index-th SkipPointer from node. More... | |
string | gdbGetNode (SkipNode *node) const |
A function that will get the current node's next and previous node's keys at each level Used because STL containers don't play well with gdb. More... | |
void | gdbPrintNode (SkipNode *node) const |
A function that will print out the current node's next and previous node's keys at each level Used because STL containers don't play well with gdb. More... | |
A sorted Skip List class.
SkipList::SkipList | ( | ) |
Default constructs the SkipList.
Uses two sentinel nodes, each initially of height 1
SkipList::SkipList | ( | int | probability, |
int | maxlevel | ||
) |
Constructs an empty list with the specified probability and maxlevel.
probability | The probability of increasing the height of a node |
maxlevel | The maximum allowable height of the skiplist |
SkipList::SkipList | ( | int | key, |
HSLAPixel | value | ||
) |
Constructs the SkipList with one initial node, which is constructed with the provided values.
key | The key to associate with the initial node |
value | The pixel to associate with the initial node |
SkipList::SkipList | ( | int | key, |
HSLAPixel | value, | ||
int | probability, | ||
int | maxlevel | ||
) |
Constructs the SkipList with one initial node, which is constructed with the provided values.
Also sets probability and maxlevel of the skiplist
key | The key to associate with the initial node |
value | The pixel to associate with the initial node |
probability | The probability of increasing the height of a node |
maxlevel | The maximum allowable height of the skiplist |
SkipList::SkipList | ( | const SkipList & | other | ) |
void SkipList::insert | ( | int | key, |
HSLAPixel | value | ||
) |
Inserts a new node into the sorted order in the list, initialized with the provided values.
key | The key to associate with the new Node |
value | The value to associate with the new Node |
Will replace the value at key if it already exists
key | The key to associate with the new Node |
value | The value to associate with the new Node |
bool SkipList::remove | ( | int | key | ) |
Removes the node with the given key from the list.
key | The key to search for and remove from the list |
PNG SkipList::makeImage | ( | int | imgSize, |
HSLAPixel | fg, | ||
HSLAPixel | bg | ||
) |
Makes and returns an image showing how degenerate the list is.
The less degenerate the faster and more efficient the skip list will be. More black pixels in the image == more degenerate
imgSize | How large to make each side of the image |
fg | The color of the foreground, or degenerate pixels in this case |
bg | The color of the background, or normal pixels in this case |
int SkipList::levelGenerator | ( | ) |
Returns the height to use for the next node.
Is based on the probability and maxLevels global variables
void SkipList::printKeys | ( | ) |
A function that prints the keys of the list using only next pointers.
HSLAPixel SkipList::search | ( | int | key | ) |
A function that searches for the given key and returns the associated HSLAPixel Returns (0, 0, 0, 50) if it's not found.
A function that searches for the given key and returns the associated HSLAPixel Returns (0, 0, 0, 0.5) if it's not found.
key | The key to search for |
key | The key to search for |
void SkipList::printKeysReverse | ( | ) |
A function that prints the keys in the list using only prev pointers.
vector< int > SkipList::traverse | ( | ) |
A function that returns the keys of the list in a vector, using only next pointers.
vector< int > SkipList::traverseReverse | ( | ) |
A function that returns the keys of the list in a vector, using only prev pointers.
PNG SkipList::toPNG | ( | int | maxHeight = 100 , |
HSLAPixel | fg = HSLAPixel(0, 0, 0) , |
||
HSLAPixel | bg = HSLAPixel(0, 0, 1) |
||
) | const |
A function that returns a PNG showing the structure of the current list NOTE: This draws the sentinel nodes as well.
maxHeight | the height of the PNG; scales heights into the range [0, maxHeight) |
fg | The color to draw the nodes |
bg | The color of the background |
|
private |
Finds the given key in the list if it exists, and returns a pointer to the node containing it.
key | The key to search for in the list |
Helper function for findR.
key | The key to search for |
level | The level we're searching through |
curr | The current node we're searching through |
|
private |
An iterative find function.
key | The key to search for |
|
private |
Finds the given key in the list if it exists, and returns a pointer to the node containing it.
Randomly calls findR or findI
key | The key to search for in the list |
|
private |
A helper function for printKeysReverse().
curr | The current node we are printing |
A helper function for traverseReverse()
curr | The current node |
out | The vector we are adding to |
|
private |
Clears up all memory associated with this SkipList.
|
private |
|
private |
A function that will return the index-th SkipPointer from node.
Used because STL containers don't play well with gdb
node | The node to consider |
index | The level of the node to get a SkipPointer for |
A function that will get the current node's next and previous node's keys at each level Used because STL containers don't play well with gdb.
node | The node to get out |
|
private |
A function that will print out the current node's next and previous node's keys at each level Used because STL containers don't play well with gdb.
Note that this doesn't work well if you are using layour src
node | The node to print out |