Class: Containers::CRBTreeMap

Inherits:
Object
  • Object
show all
Defined in:
ext/containers/rbtree_map/rbtree.c

Instance Method Summary collapse

Constructor Details

#initializeObject



302
303
304
305
# File 'ext/containers/rbtree_map/rbtree.c', line 302

static VALUE rbtree_init(VALUE self)
{
	return self;
}

Instance Method Details

#delete(key) ⇒ Object



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'ext/containers/rbtree_map/rbtree.c', line 387

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_maxObject



421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'ext/containers/rbtree_map/rbtree.c', line 421

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_minObject



404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'ext/containers/rbtree_map/rbtree.c', line 404

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;
}

#eachObject



442
443
444
445
446
# File 'ext/containers/rbtree_map/rbtree.c', line 442

static VALUE rbtree_each(VALUE self) {
	rbtree *tree = get_tree_from_self(self);
	rbt_each(tree, &rbtree_each_helper, NULL);
	return self;
}

#empty?Boolean

Returns:

  • (Boolean)


352
353
354
355
# File 'ext/containers/rbtree_map/rbtree.c', line 352

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: []



342
343
344
345
# File 'ext/containers/rbtree_map/rbtree.c', line 342

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

Returns:

  • (Boolean)


362
363
364
365
366
367
368
369
# File 'ext/containers/rbtree_map/rbtree.c', line 362

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;
}

#heightObject



357
358
359
360
# File 'ext/containers/rbtree_map/rbtree.c', line 357

static VALUE rbtree_height(VALUE self) {
	rbtree *tree = get_tree_from_self(self);
	return INT2NUM(height(tree->root));
}

#max_keyObject



379
380
381
382
383
384
385
# File 'ext/containers/rbtree_map/rbtree.c', line 379

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_keyObject



371
372
373
374
375
376
377
# File 'ext/containers/rbtree_map/rbtree.c', line 371

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: []=



336
337
338
339
340
# File 'ext/containers/rbtree_map/rbtree.c', line 336

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;
}

#sizeObject



347
348
349
350
# File 'ext/containers/rbtree_map/rbtree.c', line 347

static VALUE rbtree_size(VALUE self) {
	rbtree *tree = get_tree_from_self(self);
	return INT2NUM(size(tree->root));
}