Example #1
0
int main(int argc, char **argv) {
    struct paging_state *s = (struct paging_state *) malloc(sizeof(struct paging_state));
    // Create Pointer to Pointer to the Root Node.
    s->phys_to_virt = (struct avl_node **) malloc(sizeof(struct avl_node *));
    s->virt_to_phys = (struct avl_node **) malloc(sizeof(struct avl_node *));

    int verbose = atoi(argv[1]);
    int no = atoi(argv[2]);
    long cop[no];
    long x;

    for(int i = 0; i < no; i++){
        scanf("%lu", &x);
        cop[i] = x;
        insert_mapping(s, x, x);
        if(verbose){
            printf("inserted %lu\n", x);
            //struct avl_node *root = *(s->phys_to_virt);
            //printf("Pointer to Tree Root: %p\n", s->phys_to_virt);
            //printf("Pointer to Root Node: %p\n", *(s->phys_to_virt));
            //printf("Current Root Node Value: %lu\n", (root->mapping->paddr));
        }
    }

    for(int i = 0; i < no; i++){
        addr_t res = avl_lookup(s, cop[i]);
        // printf("looking up %lu\n", cop[i]);
        if(verbose)
            printf("Found %lu (%i/%i)\n", res,  i, no);
    }
    if (verbose)
        printf("FOUND TRACE COMPLETE\n");

    for (int i = 0; i < no; i++) {
        if (verbose)
            printf("Removing %lu\n", cop[i]);
        remove_mapping(s, cop[i], cop[i]);
        if (verbose)
            printf("Removed %lu\n", cop[i]);
    }

    if (verbose)
        printf("Testing Complete\n");

    //clean_tree(*(s->virt_to_phys), false);
    //clean_tree(*(s->phys_to_virt), true);
}
Example #2
0
int Table::read_file(const string &filename) {

    pair<map<string, size_t>::iterator, bool> ret;

    reset();
    
    istream *infile;

    if (filename.empty()) {
      infile = &cin;
    } else {
      infile = new ifstream(filename.c_str());
      if (!infile) {
          error("Cannot open file", filename.c_str());
      }
    }
    
    size_t delim_len = delim.length();
    size_t linenum = 0;
    string line; // current line
    while (getline(*infile, line)) {
        string from, to; // from and to fields
        size_t from_idx, to_idx; // indices of from and to nodes
        size_t pos = line.find(delim);
        if (pos != string::npos) {
            from = line.substr(0, pos);
            trim(from);
            if (!numeric) {
                from_idx = insert_mapping(from);
            } else {
                from_idx = strtol(from.c_str(), NULL, 10);
            }
            to = line.substr(pos + delim_len);
            trim(to);
            if (!numeric) {
                to_idx = insert_mapping(to);
            } else {
                to_idx = strtol(to.c_str(), NULL, 10);
            }
            add_arc(from_idx, to_idx);
        }

        linenum++;
        if (linenum && ((linenum % 100000) == 0)) {
            cerr << "read " << linenum << " lines, "
                 << rows.size() << " vertices" << endl;
        }

        from.clear();
        to.clear();
        line.clear();
    }

    cerr << "read " << linenum << " lines, "
         << rows.size() << " vertices" << endl;

    nodes_to_idx.clear();

    if (infile != &cin) {
        delete infile;
    }
    reserve(idx_to_nodes.size());
    
    return 0;
}