CSci-E26 Section Notes 2021-10-18

Table of Contents

1 WordFreq HW

1.1 General Data Hiding in C

// header widget.h

typedef struct widget Widget;

// functions for widgets
Widget *create_widget(...);
void destroy_widget(Widget *);
int use_widget_somehow(Widget *, ...);

// header widget_impl.h (if more than one implementation file needed
// otherwise this goes in widget.c
#include "widget.h"

// internal layout of widget struct
struct widget {
    char *name;
    int   stuff;
    ...
};

// declare common internal functions used by more than one widget file
void super_secret_widget_func(Widget *);

// widget1.c
#include "widget_impl.h"

// implement widget functions...

1.2 Wlfiler abstracting getting head of list

// wlfilerX.c
...

static struct link *get_head(char *word);


int insert(char *word, int value)
{
    struct link *prev = get_head(word);

    struct link *curr = prev->next;

      // some loopz
}


static struct link *get_head(char *word) {
    ...
    return &heads[first_letter];
};

Author: Alexis Layton

Created: 2021-10-18 Mon 20:36

Validate