Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #9861

HID: LIST list arrays

From "digi_cs" <cosmogen@gmail.com>
Subject HID: LIST list arrays
Newsgroups comp.lang.awk
Date 2024-10-17 08:23 +0300
Message-ID <6710a04a$0$705$14726298@news.sunsite.dk> (permalink)
Organization SunSITE.dk - Supporting Open source

Show all headers | View raw


Hello!

FYI

	@include “github.com/digics/UID10/uid.lib”	

	LIST = hid::get( “LIST” )


An array (A) in AWK can represent a list of unique items with an undefined order.
To introduce the concept of an array with a defined sequence of its indexes (items),
we need to specify this sequence in a subarray A[LIST] as a simple list:

The element A[ LIST ][ "" ] stores the index of the first item in the list:
	
	# items of A: first, next and last:

	A[ LIST ][ “” ] = “first”
                A[ LIST  [ “first” ] = “next”
           	A[ LIST ][ “next” ] = “last”
           	A[ LIST ][ “last” [ = “”

	A [ “first” ]...
	 A[ “next” ]...
	 A[ “last” ]...

Thus, instead of a for-in loop for array A, we use: 

	i = “”
	while ( “” != i = A[ LIST][ i ] )

		# process A[ i ]

or

	for ( i = “”; “” != i = A[ LIST ][ i ]; ) 

		# process A[ i ]

At the same time, we can still work with the main array in a for-in loop — with one caveat: 

	for ( i in A )
	
		if ( i in HID )

			continue		# this is hid (LIST)

		else

			# process A[ i ]

In case a bidirectional list is needed, another subarray A[LIST][LIST] is created
within the subarray A[LIST], where the items are listed in reverse order,
 and the element A[LIST][LIST][""] stores the index of the last item in the list. 

best regards)


--------------=  Posted using GrabIt  =----------------
------=  Binary Usenet downloading made easy =---------
-=  Get GrabIt for free from https://www.shemes.com/  =-

Back to comp.lang.awk | Previous | NextNext in thread | Find similar


Thread

HID: LIST list arrays "digi_cs" <cosmogen@gmail.com> - 2024-10-17 08:23 +0300
  Re: HID: LIST list arrays Kaz Kylheku <643-408-1753@kylheku.com> - 2024-10-18 18:58 +0000
    broken quotes, was Re: HID: LIST list arrays dave_thompson_2@comcast.net - 2024-10-20 06:49 -0400

csiph-web