CS360 Midterm -- October 18, 2000. Cheat Sheet

Red-Black Trees

typedef struct jrb_node {
  ...
  struct jrb_node *flink;
  struct jrb_node *blink;
  Jval key;
  Jval val;
} *JRB;

extern JRB make_jrb();   /* Creates a new rb-tree */

extern JRB jrb_insert_str(JRB tree, char *key, Jval val);
extern JRB jrb_insert_int(JRB tree, int ikey, Jval val);
extern JRB jrb_insert_dbl(JRB tree, double dkey, Jval val); 
extern JRB jrb_insert_gen(JRB tree, Jval key, Jval val, int (*func)(Jval,Jval));

extern JRB jrb_find_str(JRB root, char *key);
extern JRB jrb_find_int(JRB root, int ikey);
extern JRB jrb_find_dbl(JRB root, double dkey);
extern JRB jrb_find_gen(JRB root, Jval, int (*func)(Jval, Jval));

extern void jrb_delete_node(JRB node);  /* Deletes and frees a node (but
                                              not the key or val) */
extern void jrb_free_tree(JRB root);  /* Deletes and frees an entire tree */

#define jrb_traverse(ptr, lst) \
  for(ptr = jrb_first(lst); ptr != jrb_nil(lst); ptr = jrb_next(ptr))

#define jrb_rtraverse(ptr, lst) \
  for(ptr = jrb_last(lst); ptr != jrb_nil(lst); ptr = jrb_prev(ptr))

Jvals

typedef union {
  int i;
  char *s;
  void *v;
  double d;
  ....
} Jval;

Jval new_jval_i(int);
Jval new_jval_s(char *);
Jval new_jval_v(void *);

extern Jval JNULL;


Stat

Here are relevant fields for the stat struct:
struct stat {
  int    st_size;
  int    st_ino;
  int    st_mode;
  int    st_nlink;
  time_t st_atime;   /* These are ints */
  time_t st_mtime;
  ...
}

S_ISDIR(int) -- returns whether or not the given mode is a directory.

int stat(char *name, struct stat *buf);    /* Returns 0 if ok */
int lstat(char *name, struct stat *buf);   /* Returns 0 if ok */

Opendir/Readdir/Closedir

Here are relevant fields for the dirent struct:
struct dirent {
  char   d_name[256];
...
}

DIR *opendir(char *name);          /* Returns NULL on an error */
int closedir(DIR *d);
struct dirent *readdir(DIR *d);    /* Returns NULL when there are no more
                                      directory listings */