Class: Containers::CSplayTreeMap

Inherits:
Object
  • Object
show all
Defined in:
ext/containers/splaytree_map/splaytree.c

Instance Method Summary collapse

Constructor Details

#initializeObject



221
222
223
224
# File 'ext/containers/splaytree_map/splaytree.c', line 221

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

Instance Method Details

#clearObject



327
328
329
330
331
332
333
334
# File 'ext/containers/splaytree_map/splaytree.c', line 327

static VALUE splaytree_clear(VALUE self) {
	splaytree *tree = get_tree_from_self(self);
	recursively_free_nodes(tree->root);
	tree->root = NULL;
	tree->size = 0;
	
	return Qnil;
}

#delete(key) ⇒ Object



319
320
321
322
323
324
325
# File 'ext/containers/splaytree_map/splaytree.c', line 319

static VALUE splaytree_delete(VALUE self, VALUE key) {
	splaytree *tree = get_tree_from_self(self);
	if(!tree->root)
		return Qnil;
	
	return delete(tree, key);
}

#eachObject



340
341
342
343
344
# File 'ext/containers/splaytree_map/splaytree.c', line 340

static VALUE splaytree_each(VALUE self) {
	splaytree *tree = get_tree_from_self(self);
	splay_each(tree, &splaytree_each_helper, NULL);
	return self;
}

#empty?Boolean

Returns:

  • (Boolean)


272
273
274
275
# File 'ext/containers/splaytree_map/splaytree.c', line 272

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



262
263
264
265
# File 'ext/containers/splaytree_map/splaytree.c', line 262

static VALUE splaytree_get(VALUE self, VALUE key) {
	splaytree *tree = get_tree_from_self(self);
	return get(tree, key);
}

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


282
283
284
285
286
287
288
289
# File 'ext/containers/splaytree_map/splaytree.c', line 282

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

#heightObject



277
278
279
280
# File 'ext/containers/splaytree_map/splaytree.c', line 277

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

#max_keyObject



305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'ext/containers/splaytree_map/splaytree.c', line 305

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_keyObject



291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'ext/containers/splaytree_map/splaytree.c', line 291

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



256
257
258
259
260
# File 'ext/containers/splaytree_map/splaytree.c', line 256

static VALUE splaytree_push(VALUE self, VALUE key, VALUE value) {
	splaytree *tree = get_tree_from_self(self);
	insert(tree, key, value);
	return value;
}

#sizeObject



267
268
269
270
# File 'ext/containers/splaytree_map/splaytree.c', line 267

static VALUE splaytree_size(VALUE self) {
	splaytree *tree = get_tree_from_self(self);
	return INT2NUM(tree->size);
}