Exposes functions to help profile or debug Arrays.

Redefined classes

redef class Array[E: nullable Object]

array_debug :: array_debug $ Array

Resizable one dimension array of objects.
redef class Sys

array_debug :: array_debug $ Sys

The main class of the program.

All class definitions

redef class Array[E: nullable Object]

array_debug :: array_debug $ Array

Resizable one dimension array of objects.
redef class Sys

array_debug :: array_debug $ Sys

The main class of the program.
package_diagram array_debug::array_debug array_debug counter counter array_debug::array_debug->counter poset poset counter->poset ...poset ... ...poset->poset a_star-m a_star-m a_star-m->array_debug::array_debug


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 core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
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 meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
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 serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
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


module counter

counter :: counter

Simple numerical statistical analysis and presentation


module a_star-m


# Exposes functions to help profile or debug Arrays.
module array_debug

import counter

redef class Sys

	# Tracks the average length of the Strings of an array when calling to_s
	var arr_s_len = new Counter[Int]

	# Keeps the average length of an Array when calling to_s
	var arr_len = new Counter[Int]

	# Compute the average array length.
	fun avg_arr_len: Float do
		var total = 0
		var sum = 0
		for i in arr_len.keys do
			total += arr_len[i]
			sum += arr_len[i] * i
		return sum.to_f / total.to_f

	# Compute the average string length.
	fun avg_s_len: Float do
		var total = 0
		var sum = 0
		for i in arr_s_len.keys do
			total += arr_s_len[i]
			sum += arr_s_len[i] * i
		return sum.to_f / total.to_f

	# Display statistics in standard output.
	fun print_stats do
		if arr_len.sum == 0 then
			print "*** No Array stats ***"
		print "*** Array Stats ***"
		print "Number of calls to Array::to_s : {sys.arr_len.sum}"
		print "Average number of elements in an Array (when calling to_s) : {sys.avg_arr_len}"
		print "Average string size in Array : {sys.avg_s_len}"
		print "*** End of Stats ***"

	redef fun run do

redef fun exit(i)

redef class Array[E]

	redef fun to_s do
		sys.arr_len.inc length
		for i in self do
			sys.arr_s_len.inc i.to_s.length
		return super