Re: help needed
- From: Jerry Avins <jya@xxxxxxxx>
- Date: Fri, 16 Mar 2007 13:59:21 -0400
Jerry Avins wrote:
dew wrote:
...
Yes, i will be storing only a few string on the database of specified
length.and yes, linear search would do.and like u said, i don think
packing is necessary.
All right. Whether you use pointer arithmetic or array notation, set up the database to look like a two-dimensional array of chars; an array of strings. For linear search, null termination is nearly as efficient as a stored count and will probably produce simpler code. Making the string storage large enough to append a NULL to the longest entry will make a test for maximum length unnecessary. A NULL then always terminates the comparison.
Set the database-entry index to zero (first element).
Get the first character of the database entry. Of it is NULL go on to the next database entry. Without this test, a NULL password will pass unless all database entries contain valid passwords.
1) Set character index to zero.
2) Compare the indexed character of the buffer to the indexed character
of the database entry.
If they match, compare to NULL
If it is NULL, you have a valid password; exit(FOUND)
Otherwise, advance the character index
Otherwise, advance the database-entry index;
set the character index to zero
3) If the data-base index is still in bounds go to (2)
Otherwise exit(NO_MATCH)
Remarks: the buffer and data-base areas should be cleared to NULL before being loaded with data. (If it isn't data, it's NULL.)
CAVEAT: I haven't actually coded this. Take it for what it's worth.
A bug in the numbering, and an efficiency by reordering:
1) Set the database-entry index to zero (first element).
2) Set character index to zero.
3) Get the first character of the database entry. Of it is NULL go on to
the next database entry. Without this test, a NULL password will pass
unless all database entries contain valid passwords.
4) Compare the indexed character of the buffer to the indexed character
of the database entry.
If they match, compare to NULL
If it is NULL, you have a valid password; exit(FOUND)
Otherwise, advance the character index
Otherwise, advance the database-entry index
5) If the data-base index is still in bounds go to (2)
Otherwise exit(NO_MATCH)
Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
.
- Follow-Ups:
- Re: help needed
- From: dew
- Re: help needed
- From: dew
- Re: help needed
- References:
- help needed
- From: dew
- Re: help needed
- From: Jerry Avins
- Re: help needed
- From: dew
- Re: help needed
- From: Jerry Avins
- Re: help needed
- From: dew
- Re: help needed
- From: Jerry Avins
- help needed
- Prev by Date: Re: Voice conversion
- Next by Date: Re: OFDM and ISI
- Previous by thread: Re: help needed
- Next by thread: Re: help needed
- Index(es):
Relevant Pages
|