当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript rbtree.RBTree类代码示例

本文整理汇总了TypeScript中datastructures/rbtree.RBTree的典型用法代码示例。如果您正苦于以下问题:TypeScript RBTree类的具体用法?TypeScript RBTree怎么用?TypeScript RBTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RBTree类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

		it('can be given a custom compare function', function() {
			const tree = new RBTree(stringCompare)

			tree.insert('foo')
			tree.insert('bar')
			tree.insert('bazz')
			tree.insert('A')
			tree.insert('a')

			expect(tree.keys()).toEqual(['a', 'A', 'bar', 'bazz', 'foo'])
		})
开发者ID:trivial-space,项目名称:libs,代码行数:11,代码来源:rbtree.test.ts

示例2: describe

	describe('numberical', function() {
		let tree: RBTree<N, any>

		beforeEach(function() {
			tree = new RBTree(numericalCompare)
		})

		it('is initially empty', function() {
			expect(tree.root).toBe(tree.nil)
		})

		it('can insert nodes', function() {
			tree.insert(3)
			tree.insert(4, 'foo')
			tree.insert(2)

			expect(tree.root).not.toBe(tree.nil)
			expect(tree.root.key).toBe(3)
			expect(tree.root.left.key).toBe(2)
			expect(tree.root.right.key).toBe(4)
			expect(tree.root.right.value).toBe('foo')
			expect(tree.root.left.value).toBeUndefined
		})

		it('can get sorted keys', function() {
			tree.insert(3)
			tree.insert(4, 'foo')
			tree.insert(2)

			expect(tree.keys()).toEqual([2, 3, 4])
		})

		it('can search for a key', function() {
			tree.insert(3)
			tree.insert(4, 'foo')

			expect(tree.get(4)).toBe('foo')
			expect(tree.get(3)).toBeUndefined
			expect(tree.get(2)).toBe(tree.nil)
		})

		it('can retrieve the minimum and maximum', function() {
			tree.insert(3)
			tree.insert(4)
			tree.insert(2)

			expect(tree.min()).toBe(2)
			expect(tree.max()).toBe(4)
		})

		it('can remove items', function() {
			tree.insert(3)
			tree.insert(4)
			tree.insert(2)

			tree.remove(3)
			expect(tree.keys()).toEqual([2, 4])
		})

		it('has an element count', function() {
			expect(tree.size()).toBe(0)
			tree.insert(3)
			expect(tree.size()).toBe(1)
			tree.insert(4)
			expect(tree.size()).toBe(2)
			tree.insert(2)
			expect(tree.size()).toBe(3)

			tree.remove(3)
			expect(tree.size()).toBe(2)
			tree.remove(5)
			expect(tree.size()).toBe(2)
			tree.remove(2)
			expect(tree.size()).toBe(1)
			tree.remove(4)
			expect(tree.size()).toBe(0)
			tree.remove(4)
			expect(tree.size()).toBe(0)
		})
	})
开发者ID:trivial-space,项目名称:libs,代码行数:80,代码来源:rbtree.test.ts

示例3: function

		it('can get sorted keys', function() {
			tree.insert(3)
			tree.insert(4, 'foo')
			tree.insert(2)

			expect(tree.keys()).toEqual([2, 3, 4])
		})
开发者ID:trivial-space,项目名称:libs,代码行数:7,代码来源:rbtree.test.ts


注:本文中的datastructures/rbtree.RBTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。