BinarySort

Sorts records in a binary buffer.

Syntax:

BinarySort( handle, recsize, key-offset, key-size, flags )

Parameters:

(i) handle: handle of buffer.

(i) recsize: specifies the size of each record.

(i) key-offset: the offset within a record of the key field (where the first byte in the record is 0).

(i) key-size: specifies the size of the key field, in bytes.

(i) flags:  see below.

Returns:

(i) returns 1.

 

BinarySort sorts records in a binary buffer in place, updating the existing buffer. String sorts are case-insensitive.

The flags consist of a maximum of one value from each of the following groups, combined with the binary OR ("|") operator. If either (or both) is not specified, the default value will be used:

Flags

Sort sequence:

@ASCENDING (default)

@DESCENDING

 

Key type:

@STRING default

@WORD1 BYTE - 8 bit integer

@WORD2 WORD - 16-bit integer

@WORD4 DWORD - 32-bit integer

@FLOAT8 8 byte floating point number

 

Note: The binary buffer must consist of fixed-length records. Each record must contain a fixed-length key field in a fixed position.

Example:
fh=FileOpen("test.in","WRITE")
; Note: Each record is 40 chars (recsize+crlf)
; offsets.....0000000000111111111122222222223333333333
; offsets.....0123456789012345678901234567890123456789
FileWrite(fh,"0001 Flintstone Fred     (111)222-1334")
FileWrite(fh,"0002 Duck Donald         (271)333-2334")
FileWrite(fh,"0003 Duck Daffy          (222)444-3334")
FileWrite(fh,"0004 Hedgehog Sonic      (215)555-4334")
FileWrite(fh,"0005 Mario Super         (212)666-5334")
FileWrite(fh,"0006 Kent Clark          (234)777-6334")
FileWrite(fh,"0007 Lane Lois           (987)888-7334")
FileWrite(fh,"0008 Mouse Mickey        (765)999-8334")
FileWrite(fh,"0009 Coyote Wiley        (853)111-9334")
; length......0000000001111111111222222222233333333334
; length......1234567890123456789012345678901234567890
; Note that offset position and ordinal position are not the same.
FileClose(fh)
RecSize=40
NameOffset=5
NameSize=20
dbsize=FileSize("test.in")
db=BinaryAlloc(dbsize)
BinaryRead(db,"test.in")
BinarySort(db,RecSize,NameOffset,NameSize,@STRING|@ASCENDING)
BinaryWrite(db,"test.out")
BinaryFree(db)
Message("Sort Complete","Launching Notepad")
Run("Notepad.exe","test.in")
Run("Notepad.exe","test.out")
Exit
See Also:

BinaryHashRec