Skip to content

Commit

Permalink
Added .union to all array types
Browse files Browse the repository at this point in the history
  • Loading branch information
grymmjack committed Jun 8, 2024
1 parent f65edb5 commit dba6002
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 3 deletions.
34 changes: 34 additions & 0 deletions ARR/ARR_BYTE.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_BYTE.quicksort(arr%%(), start%, finish%, order%)
CALL ARR_BYTE.quicksort(arr%%(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param _BYTE ARRAY source_arr%%() array to combine
' @param _BYTE ARRAY dest_arr%%() array to store combined result
'
SUB ARR_BYTE.union(source_arr%%(), dest_arr%%())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr%%)
s_ub& = UBOUND(source_arr%%)
d_lb& = LBOUND(dest_arr%%)
d_ub& = UBOUND(dest_arr%%)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS _BYTE
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr%%(n&) = source_arr%%(i&)
NEXT i&
END SUB
34 changes: 34 additions & 0 deletions ARR/ARR_DBL.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_DBL.quicksort(arr#(), start%, finish%, order%)
CALL ARR_DBL.quicksort(arr#(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param DOUBLE ARRAY source_arr#() array to combine
' @param DOUBLE ARRAY dest_arr#() array to store combined result
'
SUB ARR_DBL.union(source_arr#(), dest_arr#())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr#)
s_ub& = UBOUND(source_arr#)
d_lb& = LBOUND(dest_arr#)
d_ub& = UBOUND(dest_arr#)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS DOUBLE
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr#(n&) = source_arr#(i&)
NEXT i&
END SUB
34 changes: 34 additions & 0 deletions ARR/ARR_FLT.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_FLT.quicksort(arr##(), start%, finish%, order%)
CALL ARR_FLT.quicksort(arr##(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param _FLOAT ARRAY source_arr##() array to combine
' @param _FLOAT ARRAY dest_arr##() array to store combined result
'
SUB ARR_FLT.union(source_arr##(), dest_arr##())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr##)
s_ub& = UBOUND(source_arr##)
d_lb& = LBOUND(dest_arr##)
d_ub& = UBOUND(dest_arr##)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS _FLOAT
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr##(n&) = source_arr##(i&)
NEXT i&
END SUB
34 changes: 34 additions & 0 deletions ARR/ARR_INT.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_INT.quicksort(arr%(), start%, finish%, order%)
CALL ARR_INT.quicksort(arr%(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param INTEGER ARRAY source_arr%() array to combine
' @param INTEGER ARRAY dest_arr%() array to store combined result
'
SUB ARR_INT.union(source_arr%(), dest_arr%())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr%)
s_ub& = UBOUND(source_arr%)
d_lb& = LBOUND(dest_arr%)
d_ub& = UBOUND(dest_arr%)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS INTEGER
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr%(n&) = source_arr%(i&)
NEXT i&
END SUB
34 changes: 34 additions & 0 deletions ARR/ARR_INT64.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_INT64.quicksort(arr&&(), start%, finish%, order%)
CALL ARR_INT64.quicksort(arr&&(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param _INTEGER64 ARRAY source_arr&&() array to combine
' @param _INTEGER64 ARRAY dest_arr&&() array to store combined result
'
SUB ARR_INT64.union(source_arr&&(), dest_arr&&())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr&&)
s_ub& = UBOUND(source_arr&&)
d_lb& = LBOUND(dest_arr&&)
d_ub& = UBOUND(dest_arr&&)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS _INTEGER64
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr&&(n&) = source_arr&&(i&)
NEXT i&
END SUB
34 changes: 34 additions & 0 deletions ARR/ARR_LONG.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_LONG.quicksort(arr&(), start%, finish%, order%)
CALL ARR_LONG.quicksort(arr&(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param LONG ARRAY source_arr&() array to combine
' @param LONG ARRAY dest_arr&() array to store combined result
'
SUB ARR_LONG.union(source_arr&(), dest_arr&())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr&)
s_ub& = UBOUND(source_arr&)
d_lb& = LBOUND(dest_arr&)
d_ub& = UBOUND(dest_arr&)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS LONG
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr&(n&) = source_arr&(i&)
NEXT i&
END SUB
34 changes: 34 additions & 0 deletions ARR/ARR_SNG.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_SNG.quicksort(arr!(), start%, finish%, order%)
CALL ARR_SNG.quicksort(arr!(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param SINGLE ARRAY source_arr!() array to combine
' @param SINGLE ARRAY dest_arr!() array to store combined result
'
SUB ARR_SNG.union(source_arr!(), dest_arr!())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr!)
s_ub& = UBOUND(source_arr!)
d_lb& = LBOUND(dest_arr!)
d_ub& = UBOUND(dest_arr!)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS SINGLE
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr!(n&) = source_arr!(i&)
NEXT i&
END SUB
4 changes: 2 additions & 2 deletions ARR/ARR_TEMPLATE.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ END SUB
' @param {Q} ARRAY source_arr{SY}() array to combine
' @param {Q} ARRAY dest_arr{SY}() array to store combined result
'
SUB ARR_STR.union(source_arr{SY}(), dest_arr{SY}())
SUB ARR_{UT}.union(source_arr{SY}(), dest_arr{SY}())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
Expand All @@ -846,7 +846,7 @@ SUB ARR_STR.union(source_arr{SY}(), dest_arr{SY}())
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS STRING
REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS {Q}
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr{SY}(n&) = source_arr{SY}(i&)
Expand Down
34 changes: 34 additions & 0 deletions ARR/ARR_UBYTE.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_UBYTE.quicksort(arr~%%(), start%, finish%, order%)
CALL ARR_UBYTE.quicksort(arr~%%(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param _UNSIGNED _BYTE ARRAY source_arr~%%() array to combine
' @param _UNSIGNED _BYTE ARRAY dest_arr~%%() array to store combined result
'
SUB ARR_UBYTE.union(source_arr~%%(), dest_arr~%%())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr~%%)
s_ub& = UBOUND(source_arr~%%)
d_lb& = LBOUND(dest_arr~%%)
d_ub& = UBOUND(dest_arr~%%)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS _UNSIGNED _BYTE
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr~%%(n&) = source_arr~%%(i&)
NEXT i&
END SUB
34 changes: 34 additions & 0 deletions ARR/ARR_UINT.BAS
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,37 @@ SUB ARR_UINT.quicksort(arr~%(), start%, finish%, order%)
CALL ARR_UINT.quicksort(arr~%(), pivot% + 1, finish%, order%)
END IF
END SUB



''
' Combine two arrays - requires both array indexes are serial with no gaps
'
' @param _UNSIGNED INTEGER ARRAY source_arr~%() array to combine
' @param _UNSIGNED INTEGER ARRAY dest_arr~%() array to store combined result
'
SUB ARR_UINT.union(source_arr~%(), dest_arr~%())
's = source, d = dest, n = new
'lb = lower bounds, ub = upper bounds
't = total elements
DIM AS LONG s_ub, s_lb, s_t
DIM AS LONG d_ub, d_lb, d_t
DIM AS LONG n_lb, n_ub, n_t
DIM AS LONG i, n

s_lb& = LBOUND(source_arr~%)
s_ub& = UBOUND(source_arr~%)
d_lb& = LBOUND(dest_arr~%)
d_ub& = UBOUND(dest_arr~%)
s_t& = (s_ub& - s_lb&)
d_t& = (d_ub& - d_lb&)
n_t& = s_t& + d_t&
n_lb& = d_lb&
n_ub& = d_ub& + s_t& + 1

REDIM _PRESERVE dest_arr(n_lb& TO n_ub&) AS _UNSIGNED INTEGER
FOR i& = s_lb& TO s_ub&
n& = d_ub& + 1 + i& - s_lb&
dest_arr~%(n&) = source_arr~%(i&)
NEXT i&
END SUB
Loading

0 comments on commit dba6002

Please sign in to comment.