<commit_before># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2012 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Pre order sets and partial order set (ie hierarchies)
module poset

# Preorder set graph.
# This class modelize an incremental preorder graph where new node and edges can be added (but no removal)
# Preorder graph has two caracteristics:
#  * reflexivity: an element is in relation with itself (ie `self.has(e)' implies `self.has_edge(e,e)')
#  * transitivity: `self.has_edge(e,f)' and `self.has_edge(f,g)' implies `self.has_edge(e,g)'
class POSet[E: Object]
	super NaiveCollection[E]

	redef fun iterator do return nodes.iterator

	# All the nodes
	private var nodes: Set[E] = new HashSet[E]
	private var tos: HashMap[E, Set[E]] = new HashMap[E, Set[E]]
	private var froms: HashMap[E, Set[E]] = new HashMap[E, Set[E]]
	private var dtos: HashMap[E, Set[E]] = new HashMap[E, Set[E]]
	private var dfroms: HashMap[E, Set[E]] = new HashMap[E, Set[E]]
	private var elements: HashMap[E, POSetElement[E]] = new HashMap[E, POSetElement[E]]

	# Add a node (an element) to the posed
	# The new element is added unconnected to any other nodes (it is both a new root and a new leaf).
	# Return the POSetElement associated to `e'.
	# If `e' is already present in the POSet then just return the POSetElement (usually you will prefer []) is this case.
	fun add_node(e: E): POSetElement[E]
	do
		if nodes.has(e) then return self.elements[e]
		nodes.add(e)
		tos[e] = new HashSet[E]
		tos[e].add(e)
		froms[e] = new HashSet[E]
		froms[e].add(e)
		dtos[e] = new HashSet[E]
		dfroms[e] = new HashSet[E]
		var poe = new POSetElement[E](self, e, nodes.length)
		self.elements[e] = poe
		return poe<commit_msg>poset: implements "has" to avoid using the NaiveCollection implementation<commit_after># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2012 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Pre order sets and partial order set (ie hierarchies)
module poset

# Preorder set graph.
# This class modelize an incremental preorder graph where new node and edges can be added (but no removal)
# Preorder graph has two caracteristics:
#  * reflexivity: an element is in relation with itself (ie `self.has(e)' implies `self.has_edge(e,e)')
#  * transitivity: `self.has_edge(e,f)' and `self.has_edge(f,g)' implies `self.has_edge(e,g)'
class POSet[E: Object]
	super NaiveCollection[E]

	redef fun iterator do return nodes.iterator

	# All the nodes
	private var nodes: Set[E] = new HashSet[E]
	private var tos: HashMap[E, Set[E]] = new HashMap[E, Set[E]]
	private var froms: HashMap[E, Set[E]] = new HashMap[E, Set[E]]
	private var dtos: HashMap[E, Set[E]] = new HashMap[E, Set[E]]
	private var dfroms: HashMap[E, Set[E]] = new HashMap[E, Set[E]]
	private var elements: HashMap[E, POSetElement[E]] = new HashMap[E, POSetElement[E]]

	redef fun has(e) do return self.nodes.has(e)

	# Add a node (an element) to the posed
	# The new element is added unconnected to any other nodes (it is both a new root and a new leaf).
	# Return the POSetElement associated to `e'.
	# If `e' is already present in the POSet then just return the POSetElement (usually you will prefer []) is this case.
	fun add_node(e: E): POSetElement[E]
	do
		if nodes.has(e) then return self.elements[e]
		nodes.add(e)
		tos[e] = new HashSet[E]
		tos[e].add(e)
		froms[e] = new HashSet[E]
		froms[e].add(e)
		dtos[e] = new HashSet[E]
		dfroms[e] = new HashSet[E]
		var poe = new POSetElement[E](self, e, nodes.length)
		self.elements[e] = poe
		return poe
{'fraction_non_alphanumeric': 0.11149750054336013, 'fraction_numerical': 0.003477504890241252, 'mean_word_length': 4.395076201641266, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6365413', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1505, 'n_words': 601}