|
of_find
|
|
Full name
|
pfc_n_cst_list.of_find
|
Access
|
public
|
Extend of
|
integer
|
Return value
|
integer
|
Prototype
|
public function integer of_find(ref n_cst_linkedlistnode,n_cst_linkedlistnode,n_cst_linkedlistnode)
|
Name
|
Datatype
|
FOUND
|
integer
|
lnv_node
|
n_cst_linkedlistnode
|
lnv_nonvalid
|
n_cst_linkedlistnode
|
NOT_FOUND
|
integer
|
public function integer of_find (ref n_cst_linkedlistnode anv_returningnode, n_cst_linkedlistnode anv_keynode, n_cst_linkedlistnode anv_startnode);//////////////////////////////////////////////////////////////////////////////
//
// Function: of_find
//
// Access: public
//
// Arguments :
// anv_returningnode (by reference) node found and returned from the list.
// anv_keynode Node containing the key to be used to lookup the requested node.
// anv_startnode The node to start the searching.
//
// Returns: integer
// 1 : found
// 0 : not found
// -1 : failure
//
// Description:
// Finds and returns reference of the next node in the list in which the key
// meets a specified condition.
//
// Note:
// The find operation will not include the valid startnode. The search starts
// on the next node.
// To start a search begining on the Head node call the function with an invalid
// startnode.
//
//////////////////////////////////////////////////////////////////////////////
//
// Revision History
//
// Version
// 6.0 Initial version
//
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1996-1997 Sybase, Inc. and its subsidiaries. All rights reserved.
// Any distribution of the PowerBuilder Foundation Classes (PFC)
// source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////
constant integer FOUND = 1
constant integer NOT_FOUND = 0
n_cst_linkedlistnode lnv_node
n_cst_linkedlistnode lnv_nonvalid
// Clear return reference.
anv_returningnode = lnv_nonvalid
// Validate required references.
// Validation of anv_startnode is not desired. (an invalid ref means to start at top(head))
if IsNull(anv_keynode) or Not IsValid(anv_keynode) then return FAILURE
// See if this is an empty list.
If of_IsEmpty() Then
Return NOT_FOUND
End If
// Since the list is not empty, validate the Head node.
if IsNull(inv_head) or Not IsValid(inv_head) then return FAILURE
// Determine the first node to search in.
If IsValid(anv_startnode) Then
// Start looking in the next node. (skip the startnode)
anv_startnode.of_getnext(lnv_node)
Else
lnv_node = inv_head
End If
// if necessary, create the compare object.
if IsNull(inv_compare) or Not IsValid(inv_compare) then
inv_compare = create n_cst_linkedlistnodecompare
end if
// Loop looking for the node.
do while IsValid(lnv_node)
choose case inv_compare.of_compare(anv_keynode, lnv_node)
case inv_compare.EQUAL
// Entry has been found.
anv_returningnode = lnv_node
return FOUND
case inv_compare.LESSTHAN
// Depending on sort attribute.
If ib_sorted Then
// No nodes after the current entry could be a match.
return NOT_FOUND
Else
// Look at next node.
End If
case inv_compare.GREATERTHAN
// Look at next node.
end choose
lnv_node.of_getnext(lnv_node)
loop
Return NOT_FOUND
end function