<commit_before>Strict

Public

#Rem
	TODO:
		* Replace uses of 'Int' and 'Float' with 'Long' and 'Double'.
			('LongArrayView', 'DoubleArrayView', etc)
#End

' Preprocessor related:
#REGAL_UTIL_BUFFERS_BYTE_OPTIMIZATIONS = True

'#If CONFIG = "debug"
	'#REGAL_UTIL_BUFFERS_SAFE = True
'#End

' Imports (Public):
Import brl.databuffer

' Imports (Private):
Private

Import memory

Import regal.sizeof
Import regal.typetool

Import monkey.math

Public

' Interfaces:
Interface BufferView
	' Methods:
	' Nothing so far.
	
	' Properties:
	Method Data:DataBuffer() Property
	Method Offset:UInt() Property ' Int
End

' Classes:
Class ArrayView<ValueType> Implements BufferView Abstract
	' Global variable(s):
	Global NIL:ValueType
	
	' Constructor(s):
	Method New(ElementSize:UInt, Count:UInt, __Direct:Bool=False)
		Self.ElementSize = ElementSize
		Self.Data = New DataBuffer(CountInBytes(Count), __Direct)
	End
	
	Method New(ElementSize:UInt, Data:DataBuffer, OffsetInBytes:UInt=0)
		Self.Offset = OffsetInBytes
		Self.ElementSize = ElementSize
		Self.Data = Data
	End
	
	' The 'ExtraOffset' argument is used to offset from the 'View' object's offset.
	Method New(ElementSize:UInt, View:BufferView, ExtraOffset:UInt=0)
		Self.ElementSize = ElementSize
		Self.Offset = (View.Offset + ExtraOffset)
		Self.Data = View.Data
	End
	
	' Methods (Public):
	
	' If overridden, these methods must respect the 'Offset' property:
	Method Get:ValueType(Index:UInt)
		Return GetRaw(Offset + IndexToAddress(Index))
	End
	
	Method Set:Void(Index:UInt, Value:ValueType)
		SetRaw(Offset + IndexToAddress(Index), Value)
		
		Return
	End
	
	Method GetArray:Bool(Index:UInt, Output:ValueType[], Count:UInt, OutputOffset:UInt=0)
		Local ByteBounds:= OffsetIndexToAddress(Index+Count)
		
		If (ByteBounds > Size) Then
			Return False
		Endif
		
		Local OutputPosition:= OutputOffset
		
		Local Address:= OffsetIndexToAddress(Index)
		
		While (Address < ByteBounds)
			Output[OutputPosition] = GetRaw(Address)
			
			OutputPosition += 1
			
			Address += ElementSize
		Wend
		
		' Return the default response.
		Return True
	End
	
	Method GetArray:ValueType[](Index:UInt, Count:UInt, _ArrOff:UInt=0)
		Local Output:= New ValueType[_ArrOff + Count]
		
		If (Not GetArray(Index, Output, Count, _ArrOff)) Then
			Return []
		Endif
		
		Return Output
	End
	
	Method SetArray:Bool(Index:UInt, Input:ValueType[], Count:UInt, InputOffset:UInt=0)
		Local ByteBounds:= OffsetIndexToAddress(Index+Count)
		
		If (ByteBounds > Size) Then
			Return False
		Endif
		
		Local InputPosition:= InputOffset
		
		Local Address:= OffsetIndexToAddress(Index)
		
		While (Address < ByteBounds)
			SetRaw(Address, Input[InputPosition])
			
			InputPosition += 1
			
			Address += ElementSize
		Wend
		
		' Return the default response.
		Return True
	End
	
	Method Add:ValueType(Index:UInt, Value:ValueType)
		Local Result:= (Get(Index) + Value)
		
		Set(Index, Result)
		
		Return Result<commit_msg>Added quick overloads for 'SetArray'.<commit_after>Strict

Public

#Rem
	TODO:
		* Replace uses of 'Int' and 'Float' with 'Long' and 'Double'.
			('LongArrayView', 'DoubleArrayView', etc)
#End

' Preprocessor related:
#REGAL_UTIL_BUFFERS_BYTE_OPTIMIZATIONS = True

'#If CONFIG = "debug"
	'#REGAL_UTIL_BUFFERS_SAFE = True
'#End

' Imports (Public):
Import brl.databuffer

' Imports (Private):
Private

Import memory

Import regal.sizeof
Import regal.typetool

Import monkey.math

Public

' Interfaces:
Interface BufferView
	' Methods:
	' Nothing so far.
	
	' Properties:
	Method Data:DataBuffer() Property
	Method Offset:UInt() Property ' Int
End

' Classes:
Class ArrayView<ValueType> Implements BufferView Abstract
	' Global variable(s):
	Global NIL:ValueType
	
	' Constructor(s):
	Method New(ElementSize:UInt, Count:UInt, __Direct:Bool=False)
		Self.ElementSize = ElementSize
		Self.Data = New DataBuffer(CountInBytes(Count), __Direct)
	End
	
	Method New(ElementSize:UInt, Data:DataBuffer, OffsetInBytes:UInt=0)
		Self.Offset = OffsetInBytes
		Self.ElementSize = ElementSize
		Self.Data = Data
	End
	
	' The 'ExtraOffset' argument is used to offset from the 'View' object's offset.
	Method New(ElementSize:UInt, View:BufferView, ExtraOffset:UInt=0)
		Self.ElementSize = ElementSize
		Self.Offset = (View.Offset + ExtraOffset)
		Self.Data = View.Data
	End
	
	' Methods (Public):
	
	' If overridden, these methods must respect the 'Offset' property:
	Method Get:ValueType(Index:UInt)
		Return GetRaw(Offset + IndexToAddress(Index))
	End
	
	Method Set:Void(Index:UInt, Value:ValueType)
		SetRaw(Offset + IndexToAddress(Index), Value)
		
		Return
	End
	
	Method GetArray:Bool(Index:UInt, Output:ValueType[], Count:UInt, OutputOffset:UInt=0)
		Local ByteBounds:= OffsetIndexToAddress(Index+Count)
		
		If (ByteBounds > Size) Then
			Return False
		Endif
		
		Local OutputPosition:= OutputOffset
		
		Local Address:= OffsetIndexToAddress(Index)
		
		While (Address < ByteBounds)
			Output[OutputPosition] = GetRaw(Address)
			
			OutputPosition += 1
			
			Address += ElementSize
		Wend
		
		' Return the default response.
		Return True
	End
	
	Method GetArray:ValueType[](Index:UInt, Count:UInt, _ArrOff:UInt=0)
		Local Output:= New ValueType[_ArrOff + Count]
		
		If (Not GetArray(Index, Output, Count, _ArrOff)) Then
			Return []
		Endif
		
		Return Output
	End
	
	Method SetArray:Bool(Index:UInt, Input:ValueType[], Count:UInt, InputOffset:UInt=0)
		Local ByteBounds:= OffsetIndexToAddress(Index+Count)
		
		If (ByteBounds > Size) Then
			Return False
		Endif
		
		Local InputPosition:= InputOffset
		
		Local Address:= OffsetIndexToAddress(Index)
		
		While (Address < ByteBounds)
			SetRaw(Address, Input[InputPosition])
			
			InputPosition += 1
			
			Address += ElementSize
		Wend
		
		' Return the default response.
		Return True
	End
	
	Method SetArray:Bool(Index:UInt, Input:ValueType[])
		Return SetArray(Index, Input, Input.Length)
	End
	
	' TODO: Optimize this overload to bypass index conversion.
	Method SetArray:Bool(Input:ValueType[])
		Return SetArray(0, Input)
	End
	
	Method Add:ValueType(Index:UInt, Value:ValueType)
		Local Result:= (Get(Index) + Value)
		
		Set(Index, Result)
		
		Return Result
{'fraction_non_alphanumeric': 0.09795653584171261, 'fraction_numerical': 0.002432695426532598, 'mean_word_length': 4.486654804270462, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3984621', 'n_tokens_mistral': 2259, 'n_tokens_neox': 1930, 'n_words': 525}