Class: Containers::CRBTreeMap
- Inherits:
-
Object
- Object
- Containers::CRBTreeMap
- Defined in:
- ext/containers/rbtree_map/rbtree.c
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #delete_max ⇒ Object
- #delete_min ⇒ 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
307 308 309 310 |
# File 'ext/containers/rbtree_map/rbtree.c', line 307
static VALUE rbtree_init(VALUE self)
{
return self;
}
|
Instance Method Details
#delete(key) ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'ext/containers/rbtree_map/rbtree.c', line 412
static VALUE rbtree_delete(VALUE self, VALUE key) {
VALUE deleted_value;
rbtree *tree = get_tree_from_self(self);
if(!tree->root)
return Qnil;
tree->root = delete(tree, tree->root, key, &deleted_value);
if(tree->root)
tree->root->color = BLACK;
if(deleted_value) {
return deleted_value;
}
return Qnil;
}
|
#delete_max ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'ext/containers/rbtree_map/rbtree.c', line 446
static VALUE rbtree_delete_max(VALUE self) {
VALUE deleted_value;
rbtree *tree = get_tree_from_self(self);
if(!tree->root)
return Qnil;
tree->root = delete_max(tree->root, &deleted_value);
if(tree->root)
tree->root->color = BLACK;
if(deleted_value) {
return deleted_value;
}
return Qnil;
}
|
#delete_min ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'ext/containers/rbtree_map/rbtree.c', line 429
static VALUE rbtree_delete_min(VALUE self) {
VALUE deleted_value;
rbtree *tree = get_tree_from_self(self);
if(!tree->root)
return Qnil;
tree->root = delete_min(tree->root, &deleted_value);
if(tree->root)
tree->root->color = BLACK;
if(deleted_value) {
return deleted_value;
}
return Qnil;
}
|
#each ⇒ Object
467 468 469 470 471 |
# File 'ext/containers/rbtree_map/rbtree.c', line 467
static VALUE rbtree_each(VALUE self) {
rbtree *tree = get_tree_from_self(self);
rbt_each(tree, &rbtree_each_helper, NULL);
return self;
}
|
#empty? ⇒ Boolean
377 378 379 380 |
# File 'ext/containers/rbtree_map/rbtree.c', line 377
static VALUE rbtree_is_empty(VALUE self) {
rbtree *tree = get_tree_from_self(self);
return (tree->root ? Qfalse : Qtrue);
}
|
#get(key) ⇒ Object Also known as: []
367 368 369 370 |
# File 'ext/containers/rbtree_map/rbtree.c', line 367
static VALUE rbtree_get(VALUE self, VALUE key) {
rbtree *tree = get_tree_from_self(self);
return get(tree, tree->root, key);
}
|
#has_key?(key) ⇒ Boolean
387 388 389 390 391 392 393 394 |
# File 'ext/containers/rbtree_map/rbtree.c', line 387
static VALUE rbtree_has_key(VALUE self, VALUE key) {
rbtree *tree = get_tree_from_self(self);
if(!tree->root) { return Qfalse; }
if(get(tree, tree->root, key) == Qnil)
return Qfalse;
return Qtrue;
}
|
#height ⇒ Object
382 383 384 385 |
# File 'ext/containers/rbtree_map/rbtree.c', line 382
static VALUE rbtree_height(VALUE self) {
rbtree *tree = get_tree_from_self(self);
return INT2NUM(height(tree->root));
}
|
#max_key ⇒ Object
404 405 406 407 408 409 410 |
# File 'ext/containers/rbtree_map/rbtree.c', line 404
static VALUE rbtree_max_key(VALUE self) {
rbtree *tree = get_tree_from_self(self);
if(!tree->root)
return Qnil;
return max_key(tree->root);
}
|
#min_key ⇒ Object
396 397 398 399 400 401 402 |
# File 'ext/containers/rbtree_map/rbtree.c', line 396
static VALUE rbtree_min_key(VALUE self) {
rbtree *tree = get_tree_from_self(self);
if(!tree->root)
return Qnil;
return min_key(tree->root);
}
|
#push(key, value) ⇒ Object Also known as: []=
361 362 363 364 365 |
# File 'ext/containers/rbtree_map/rbtree.c', line 361
static VALUE rbtree_push(VALUE self, VALUE key, VALUE value) {
rbtree *tree = get_tree_from_self(self);
tree->root = insert(tree, tree->root, key, value);
return value;
}
|
#size ⇒ Object
372 373 374 375 |
# File 'ext/containers/rbtree_map/rbtree.c', line 372
static VALUE rbtree_size(VALUE self) {
rbtree *tree = get_tree_from_self(self);
return INT2NUM(size(tree->root));
}
|