entry* table[ TABLE_SIZE ] = { NULL }; this statement initializes the "table" array as a TABLE_SIZE (7) element array with NULL pointers. In C arrays are indexed from zero so we end up with:
I use (Undefined) here, as the table array element contains a NULL pointer. In the context of this code (empty) could be a better analogy.
The insert code calculates a hash value of the input string being the length of the string modulo the TABLE_SIZE (7). This is a pretty simple hash which results in strings of various lengths being inserted into the table array as follows:
Looking at this code in the insert function:
we can see that each element of table is a linked list and new values are inserted at the front of the list.
So "Jaga" is inserted into the table[4] list first, then later "Kate" is inserted in front of "Jaga" then "Nash", and so forth.
Here is the update code you requested:
Thank you so much! This helps a lot =D
One last thing, would you happen to know how to run the python code? I know it's incomplete but I am not sure what to add so I can make it run and see the output.
Hello guys it's me again, I need some help. What I'm doing is listing all the file and directories Recusively and using it a a master file. Then I need to do the same the nest day to make sure nothing was deleted or modified. What happen is file in one of out major directories was deleted without... (2 Replies)
hey, im trying to write a script that will list all the .c files, and give me the first 10 lines of code in them. I think ive got that bit working, but i want to make it use friendly so i can select whether i want to modify a .c file or delete it. (7 Replies)
Hi all,
First of all compliments on the forum here. Looks great and has lots of information, some of which I have been able to use. I am a relativ noob when it comes to Unix but already I have been fooling around with scripts for the company I work for here in switzerland!
Thanks to this... (2 Replies)
Hi All I have two scripts which i used to try and list all the directories one using 'function', which only lists the first directory and does not show directories within directories.
function ListDir ()
{
for arg in $(ls $HOME)
do
if
then
echo $arg
... (2 Replies)
Hi Friend,
I have a small script to list all file FFAAAAABBBBB00001 and FFAAAAABBBBB00001.repaired (when I run another script, the orginal file will output another *.repaired file) in my unix directory, and reaname the output file FFAAAAABBBBB00001.repaired back to FFAAAABBBBB00001. However, it... (2 Replies)
EDIT : This is for perl
@data2 = grep(/$data/, @list_now);
This gives me @data2 as
Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared
But I really cant access data2 by its individual elements.
$data2 is the entire list, while $data,2,3...... (1 Reply)
Hello everyone - I have the task to create a file list script that will list files in directory based on the parameters passed to the program.
It has to be a C Shell - I mentioned that before but I got closed :) - the company only allows this shell for security purposes I guess.
Anyway, here is... (4 Replies)
Hi all,
I have a PLSQL script which has a IN list where it takes some ids as input. For example
SELECT * FROM EMPLOYEE WHERE EMPLOYEE_ID IN (comma separated list )
I want to run this quest inside a shell script but I would like to prepare the IN list dynamically where the employee ids... (1 Reply)
Is there a way I can specify the name of a list as an argument to a shell script and then use the values of that list name in the script?
I need to do this WITHOUT using case statements.
Something like this:
check.sh list1
#!/bin/bash
list1="www.amazon.com www.google.com"... (9 Replies)
Discussion started by: gctaylor
9 Replies
LEARN ABOUT ULTRIX
lsearch
lsearch(3) Library Functions Manual lsearch(3)Name
lsearch, lfind - linear search and update
Syntax
#include <search.h>
#include <sys/types.h>
void *lsearch (key, base, nelp, width, compar)
void *key;
void *base;
size_t *nelp;
size_t width;
int (*compar)( );
void *lfind (key, base, nelp, width, compar)
void *key;
void *base;
size_t *nelp;
size_t width;
int (*compar)( );
Description
The subroutine is a linear search routine generalized from Knuth (6.1) Algorithm S. It returns a pointer into a table indicating where a
datum may be found. If the datum does not occur, it is added at the end of the table. The key points to the datum to be sought in the ta-
ble. The base points to the first element in the table. The nelp points to an integer containing the current number of elements in the
table. The width is the size of an element in bytes. The integer is incremented if the datum is added to the table. The compar is the
name of the comparison function which the user must supply (strcmp, for example). It is called with two arguments that point to the ele-
ments being compared. The function must return zero if the elements are equal and non-zero otherwise.
The subroutine is the same as lsearch except that if the datum is not found, it is not added to the table. Instead, a NULL pointer is
returned. The pointers to the key and the element at the base of the table should be of type pointer-to-element, and cast to type pointer-
to-character.
The comparison function need not compare every byte, so arbitrary data may be contained in the elements in addition to the values being
compared.
Although declared as type pointer-to-character, the value returned should be cast into type pointer-to-element.
Restrictions
Undefined results can occur if there is not enough room in the table to add a new item.
Return Values
If the searched for datum is found, both and return a pointer to it. Otherwise, returns NULL and returns a pointer to the newly added ele-
ment.
See Alsobsearch(3), hsearch(3), tsearch(3)lsearch(3)