New Array Utilities Library Unit released

Yesterday I added a shiny new unit to the DelphiDabbler Code Library - the Array Utilities Unit. It lives in the ddablib/arrayutils repo on GitHub.

This unit, named DelphiDabbler.Lib.ArrayUtils.pas, provides a single "Advanced" record, TArrayUtils, that contains static methods that perform common operations on generic arrays. There are numerous overloaded versions of many of the methods. Every method operates on a given generic array that is passed as a parameter, either as an array of T or a TArray<T>.

The unit requires Delphi XE or later. It has been tested with Delphi XE and Delphi 12. The code depends only on the Delphi RTL, so it should work for any platform supported by Delphi and be both VCL and FireMonkey compatible. I've only tested Windows 32 bit and 64 bit targets.

There are far too many methods to describe in here, but you can find them all listed and explained in the comprehensive online documentation.

As a taster you'll find

  • Methods that ape some JavaScript array methods such as slice(), pop(), unshift(), reduce(), map() etc.
  • Methods that get the indices of given element values.
  • Numerous methods to search arrays for elements that match given criteria.
  • Basic sorting method.
  • Array comparison methods.
  • Methods to insert and delete array elements, where some deletion methods can free deleted objects or release deleted resources.
  • A method to make deep copies of an array.
  • etc...

Every method has a unit test, written using the DUnit framework. There's also example code for every method in the documentation. The same examples are collected together in a demo program. The source code for the unit tests and the demo project is included in the project download.

The unit was inspired by the System.Generics.Collections.TArray class from the Delphi RTL and by the similar TArrayUtils record in the DelphiDabbler Code Snippets Collection. The new unit expands on both of those pieces of code.

I'd originally decided to expand the version of TArrayUtils in the Code Snippets Collection, but the code quickly grew to such an extent it became much larger than something that could reasonably be referred to as a code snippet. So the expanded version of TArrayUtils was added to the Code Library instead, leaving the original code snippet unchanged.

⮞ Download release v0.1.0 from GitHub or Git clone the repo using https://github.com/ddablib/arrayutils.git.

Warning: this is release v0.1.0, so it's early development code. That means that (a) you need to watch out for bugs and (b) the API is subject to change. Nothing is guaranteed to stay the same across v0.x releases.

Here's an extract from the online docs for the two TArrayUtils.Chop<T> method overloads:

And here's an extract from the source code showing the implementation of the same methods:




Comments

  1. Great set of utilities, although you should know the Git repository is not available to public, and no one can access it until you change the visibility of it.

    ReplyDelete
    Replies
    1. Thx v much for pointing this out! It's now public.

      Delete

Post a Comment

Comments are very welcome, but please don't comment here if:

1) You have a query about, or a bug report for, one of my programs or libraries. Most of my posts contain a link to the relevant repository where there will be an issue tracker you can use.

2) You have a query about any 3rd party programs I feature, please address them to the developer(s) - there will be a link in the post.

3) You're one of the tiny, tiny minority who are aggressive or abusive - in the bin you go and reported you will be!

Thanks

Popular posts from this blog

Initialising dynamic arrays

Deleting elements from a dynamic array