aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/lib/movenulls.x
blob: 5e961d201bd260eaf2fde31097285bb0e43ab9de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# MOVENULLS -- Move all null elements to the end of the index array
#
# This procedure rearranges an array of row indices so that all rows with
# nulls in a particular column are moved to the end of the index array.
# The position of the nulls in the column is indicated by an array of null
# flags, whose length might be greater than the length of the array of
# indices, i.e., only a subset of the rows in a table might be in the index
# array.
#
# B.Simon	15-Dec-87	First Code

int procedure movenulls (nindex, nulflg, index) 

int	nindex		#  i: Number of indices
bool	nulflg[ARB]	#  i: Array of null flags
int	index[ARB]	# io: Array of row indices
#--
int	nelem, idx, jdx

begin
	nelem = nindex

	do idx = nindex, 1, -1 {
	    jdx = index[idx]
	    if (nulflg[jdx]) {
		if (nelem != idx) {
		    index[idx] = index[nelem]
		    index[nelem] = jdx
		}
		nelem = nelem - 1
	    }
	}

	return (nelem)
end