Class: Algorithms::Containers::CSplayTreeMap
- Inherits:
-
Object
- Object
- Algorithms::Containers::CSplayTreeMap
- Defined in:
- ext/containers/splaytree_map/splaytree.c
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #get(key) ⇒ Object (also: #[])
- #has_key?(key) ⇒ Boolean
- #height ⇒ Object
- #initialize ⇒ Object constructor
- #max_key ⇒ Object
- #min_key ⇒ Object
- #push(key, value) ⇒ Object (also: #[]=)
- #size ⇒ Object
Constructor Details
#initialize ⇒ Object
250 251 252 253 |
# File 'ext/containers/splaytree_map/splaytree.c', line 250
static VALUE splaytree_init(VALUE self)
{
return self;
}
|
Instance Method Details
#clear ⇒ Object
378 379 380 381 382 383 |
# File 'ext/containers/splaytree_map/splaytree.c', line 378
static VALUE splaytree_clear(VALUE self) {
splaytree *tree = get_tree_from_self(self);
recursively_free_nodes(tree->root);
tree->root = NULL;
return Qnil;
}
|
#delete(key) ⇒ Object
368 369 370 371 372 373 374 375 376 |
# File 'ext/containers/splaytree_map/splaytree.c', line 368
static VALUE splaytree_delete(VALUE self, VALUE key) {
VALUE deleted = Qnil;
splaytree *tree = get_tree_from_self(self);
if(!tree->root)
return Qnil;
tree->root = delete(tree, tree->root, key, &deleted);
return deleted;
}
|
#each ⇒ Object
389 390 391 392 393 |
# File 'ext/containers/splaytree_map/splaytree.c', line 389
static VALUE splaytree_each(VALUE self) {
splaytree *tree = get_tree_from_self(self);
splay_each(tree, &splaytree_each_helper, NULL);
return self;
}
|
#empty? ⇒ Boolean
321 322 323 324 |
# File 'ext/containers/splaytree_map/splaytree.c', line 321
static VALUE splaytree_is_empty(VALUE self) {
splaytree *tree = get_tree_from_self(self);
return (tree->root ? Qfalse : Qtrue);
}
|
#get(key) ⇒ Object Also known as: []
310 311 312 313 |
# File 'ext/containers/splaytree_map/splaytree.c', line 310
static VALUE splaytree_get(VALUE self, VALUE key) {
splaytree *tree = get_tree_from_self(self);
return get(tree, key);
}
|
#has_key?(key) ⇒ Boolean
331 332 333 334 335 336 337 338 |
# File 'ext/containers/splaytree_map/splaytree.c', line 331
static VALUE splaytree_has_key(VALUE self, VALUE key) {
splaytree *tree = get_tree_from_self(self);
if(!tree->root) { return Qfalse; }
if(get(tree, key) == Qnil)
return Qfalse;
return Qtrue;
}
|
#height ⇒ Object
326 327 328 329 |
# File 'ext/containers/splaytree_map/splaytree.c', line 326
static VALUE splaytree_height(VALUE self) {
splaytree *tree = get_tree_from_self(self);
return INT2NUM(height(tree->root));
}
|
#max_key ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'ext/containers/splaytree_map/splaytree.c', line 354
static VALUE splaytree_max_key(VALUE self) {
splaytree *tree = get_tree_from_self(self);
splaytree_node *node;
if(!tree->root)
return Qnil;
node = tree->root;
while (node->right)
node = node->right;
return node->key;
}
|
#min_key ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'ext/containers/splaytree_map/splaytree.c', line 340
static VALUE splaytree_min_key(VALUE self) {
splaytree *tree = get_tree_from_self(self);
splaytree_node *node;
if(!tree->root)
return Qnil;
node = tree->root;
while (node->left)
node = node->left;
return node->key;
}
|
#push(key, value) ⇒ Object Also known as: []=
304 305 306 307 308 |
# File 'ext/containers/splaytree_map/splaytree.c', line 304
static VALUE splaytree_push(VALUE self, VALUE key, VALUE value) {
splaytree *tree = get_tree_from_self(self);
tree->root = insert(tree, tree->root, key, value);
return value;
}
|
#size ⇒ Object
315 316 317 318 319 |
# File 'ext/containers/splaytree_map/splaytree.c', line 315
static VALUE splaytree_size(VALUE self) {
splaytree *tree = get_tree_from_self(self);
if(!tree->root) { return INT2NUM(0); }
return INT2NUM(tree->root->size);
}
|