BINSRCH(3WN)

πŸ’– BINSRCH(3WN) πŸ’–

okay bestie, welcome to the WordNetβ„’ Library Functions corner of the manual, where we're doing binary searches and it's giving main character energy. pull up a chair, grab a strawberry πŸ“, and let's get into it.


✨ NAME ✨

bin_search, copyfile, replace_line, insert_line β€” general purpose functions for performing a binary search πŸ¦‹


✨ SYNOPSIS ✨

char *bin_search(char *key, FILE *fp);

void copyfile(FILE *fromfp, FILE *tofp);

char *replace_line(char *new_line, char *key, FILE *fp);

char *insert_line(char *new_line, char *key, FILE *fp);

✨ DESCRIPTION ✨

so the WordNet library is carrying several general purpose functions for performing a binary search and modifying sorted files. lowkey iconic of it. πŸ‘‘

bin_search() is the primary binary search algorithm. it searches for key as the first item on a line in the file pointed to by fp. the delimiter between the key and the rest of the fields on the line, if there are any, must be a space. it returns a pointer to a static variable containing the entire line. and if there's no match? NULL. no line, no vibes. πŸ’€

the remaining functions are not used by WordNet, and are only briefly described. they're the background characters fr fr.

copyfile() copies the contents of one file to another. simple. slay.

replace_line() replaces a line in a file having searchkey key with the contents of new_line. it returns the original line, or NULL in case of error. πŸ™ˆ

insert_line() finds the proper place to insert the contents of new_line, having searchkey key, in the sorted file pointed to by fp. it returns NULL if a line with this searchkey is already in the file. no duplicates allowed bestie, we're not doing that. πŸ’…


✨ NOTES ✨

  • the maximum length of key is 1024.
  • the maximum line length in a file is 25K.
  • if there are no additional fields after the search key, the key must be followed by at least one space before the newline character. yes literally. don't skip it. 😭

✨ SEE ALSO ✨

wnintro(3WN), morph(3WN), wnsearch(3WN), wnutil(3WN), wnintro(5WN).

go read those too, they're all part of the same friend group 🫢


✨ WARNINGS ✨

okay this one is important, listen up πŸ”₯

binsearch() returns a pointer to a static character buffer. if you need the results saved, the caller should copy the returned string, because a subsequent call will replace the contents of the static buffer. so like. it's not yours to keep, bestie. copy it or lose it. no cap. πŸ’€βœ¨


and that's the whole page!! this was WordNet 3.0, from Dec 2006 πŸŽ€ thanks for reading, you ate that, periodt. πŸŒˆβ­πŸ’œ