Introduce tree structures abstraction

Trees are a widely used abstract data type (ADT) or data structure implementing this ADT that simulates a hierarchical tree structure, with a root value and subtrees of children, represented as a set of linked nodes.

Introduced classes

abstract class TreeMap[K: Comparable, E: nullable Object]

trees :: TreeMap

Abstract tree map structure
abstract class TreeNode[K: Comparable, E: nullable Object]

trees :: TreeNode

Abstract node structure used in Tree implementation

All class definitions

abstract class TreeMap[K: Comparable, E: nullable Object]

trees $ TreeMap

Abstract tree map structure
abstract class TreeNode[K: Comparable, E: nullable Object]

trees $ TreeNode

Abstract node structure used in Tree implementation
package_diagram trees::abstract_tree abstract_tree core core trees::abstract_tree->core trees::bintree bintree trees::bintree->trees::abstract_tree trees::bktree bktree trees::bktree->trees::abstract_tree trees::rbtree rbtree trees::rbtree->trees::bintree trees::rbtree... ... trees::rbtree...->trees::rbtree nitc::model_index model_index nitc::model_index->trees::bktree nitc::model_index... ... nitc::model_index...->nitc::model_index

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.

Children

module bintree

trees :: bintree

Binary Tree data-structure
module bktree

trees :: bktree

Implementation of BKTree

Descendants

module a_star-m

a_star-m

module api

nitc :: api

Components required to build a web server about the nit model.
module api_auth

nitc :: api_auth

module api_base

nitc :: api_base

Base classes used by nitweb.
module api_docdown

nitc :: api_docdown

Nitdoc specific Markdown format handling for Nitweb
module api_feedback

nitc :: api_feedback

Feedback related features
module api_light

nitc :: api_light

Highlight and collect messages from a piece of code
module api_model

nitc :: api_model

module commands_base

nitc :: commands_base

Documentation commands
module commands_catalog

nitc :: commands_catalog

Commands to retrieve Catalog related data
module commands_docdown

nitc :: commands_docdown

Doc down related queries
module commands_graph

nitc :: commands_graph

Graph commands
module commands_http

nitc :: commands_http

Initialize commands from HTTP requests
module commands_model

nitc :: commands_model

Doc commands about a Model or a MEntity
module commands_parser

nitc :: commands_parser

A parser that create DocCommand from a string
module commands_usage

nitc :: commands_usage

Commands about how mentities are used
module html_commands

nitc :: html_commands

Render commands results as HTML
module json_commands

nitc :: json_commands

Translate command results to json
module md_commands

nitc :: md_commands

Render commands results as Markdown
module model_index

nitc :: model_index

Search things from the Model
module nitdoc

nitc :: nitdoc

Generator of static API documentation for the Nit language
module nitpackage

nitc :: nitpackage

Helpful features about packages
module nitweb

nitc :: nitweb

Runs a webserver based on nitcorn that render things from model.
module nitx

nitc :: nitx

nitx, a command tool that displays useful data about Nit code
module puzzle

ai :: puzzle

The N-puzzle problem, modeled naively as a SearchProblem.
module rbtree

trees :: rbtree

A red–black tree is a data structure which is a type of self-balancing binary search tree.
module search

ai :: search

Basic framework for search problems and solver.
module static

nitc :: static

Nitdoc generation framework
module static_base

nitc :: static_base

Base entities shared by all the nitdoc code
module static_cards

nitc :: static_cards

Cards templates for the static documentation
module static_html

nitc :: static_html

Render documentation pages as HTML
module static_index

nitc :: static_index

Manage indexing of Nit model for Nitdoc QuickSearch.
module static_structure

nitc :: static_structure

Composes the pages of the static documentation
module term

nitc :: term

module trees

trees :: trees

General module for tree data structures
module trie

trees :: trie

A trie (or prefix tree) is a datastructure used to perform prefix searches.
# Introduce tree structures abstraction
# Trees are a widely used abstract data type (ADT) or data structure
# implementing this ADT that simulates a hierarchical tree structure,
# with a root value and subtrees of children, represented as a set of linked nodes.
module abstract_tree

# Abstract tree map structure
# * `K`: tree node key
# * `E`: tree node value
abstract class TreeMap[K: Comparable, E]
	super Map[K, E]

	# Type of nodes used in this tree implementation
	protected type N: TreeNode[K, E]

	# The `root` node of the tree (null if tree is empty)
	protected var root: nullable N = null is protected writable

	# Display the tree in a gaphical windows
	# Graphviz with a working -Txlib is expected
	# Used for debugging
	fun show_dot is abstract
end

# Abstract node structure used in `Tree` implementation
#
# Nodes are defined recursively each node (except the root one) pointing to a parent.
# Nodes can be used to store data with the `TreeNode::value` attribute.
#
# Formal parameters:
# * `K`: key type (a `Comparable` one so nodes can be sorted by their keys)
# * `E`: value type (to store your data)
abstract class TreeNode[K: Comparable, E]
	super Comparable

	# TreeNode type
	type N: TreeNode[K, E]

	# `key` for this node
	var key: K

	# `value` stored in the node
	var value: E

	# Direct parent of this node (`null` if the node is root)
	#
	# See `Tree::root`.
	var parent: nullable N = null is writable

	# Depth in tree (length of the path from `self` to `root`)
	fun depth: Int do
		var node = parent
		var i = 0
		while node != null do
			node = node.parent
			i += 1
		end
		return i
	end

	redef fun to_s do return "\{{value or else ""}\}"

	# Return dot representation of this node
	#
	# See `Tree::show_dot`.
	fun to_dot: String do
		var res = new FlatBuffer
		res.append "\"{self}\";\n"
		if parent != null then res.append "\"{parent.as(not null)}\" -> \"{self}\"[dir=back];\n"
		return res.to_s
	end

	redef type OTHER: N

	# Nodes equality is done on `value` equality
	#
	# Redefine this method to change the default behavior.
	redef fun ==(o) do
		if not o isa N then return false
		return self.value == o.value
	end

	# Nodes ordering is based on the `key`
	redef fun <(o) do return self.key < o.key
end
lib/trees/abstract_tree.nit:15,1--99,3