"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

util.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include "../host.h"
#include "../misc.h"
#include "../machine.h"
#include "util.h"
#include "libcheetah.h"

Include dependency graph for util.c:

Include dependency graph

Go to the source code of this file.

Functions

Variables


Function Documentation

unsigned** idim2 int    row,
int    col
 

Definition at line 57 of file util.c.

References fatal().

Referenced by init_dmvl(), init_saclru(), and init_sacopt().

00058 {
00059   int i;
00060   register unsigned **prow, *pdata;
00061 
00062   pdata = (unsigned *)calloc(row*col, sizeof (int));
00063   if (!pdata)
00064     fatal("out of virtual memory");
00065 
00066   prow = (unsigned **)calloc(row, sizeof (int *));
00067   if (!prow)
00068     fatal("out of virtual memory");
00069 
00070   for (i=0;i<row;i++)
00071     {
00072       prow [i] = pdata;
00073       pdata += col;
00074     }
00075 
00076   return prow;
00077 }

int power int    x,
int    y
 

Definition at line 34 of file util.c.

Referenced by init_saclru().

00035 {
00036   int pwr = 1;
00037 
00038   while (y > 0)
00039     {
00040       pwr *= x;
00041       --y;
00042     }
00043   return pwr;
00044 }

void rotate_left int    y,
struct tree_node **    p_stack
 

Definition at line 119 of file util.c.

References tree_node::lft, tree_node::rt, and tree_node::rtwt.

Referenced by splay().

00120 {
00121   int x,z;
00122 
00123   z = y-1;
00124   x = y+1;
00125   if (z > 0)
00126     {
00127       if (p_stack[z]->lft == p_stack[y])
00128         p_stack[z]->lft = p_stack[x];
00129       else
00130         p_stack[z]->rt = p_stack[x];
00131     }
00132   p_stack[y]->rt = p_stack[x]->lft;
00133   p_stack[y]->rtwt -= p_stack[x]->rtwt + 1;
00134   p_stack[x]->lft = p_stack[y];
00135   p_stack[y] = p_stack[x];
00136   p_stack[x] = p_stack[x+1];
00137 }

void rotate_right int    y,
struct tree_node **    p_stack
 

Definition at line 149 of file util.c.

References tree_node::lft, tree_node::rt, and tree_node::rtwt.

Referenced by splay().

00150 {
00151   int x,z;
00152   register struct tree_node *t1, *t2, *t3;
00153 
00154   z = y-1;
00155   x = y+1;
00156   t1 = p_stack[x];
00157   t2 = p_stack[y];
00158   t3 = p_stack[z];
00159   if (z>0)
00160     {
00161       if (t3->lft == t2)
00162         t3->lft = t1;
00163       else
00164         t3->rt = t1;
00165     }
00166   t2->lft = t1->rt;
00167   t1->rt = t2;
00168   t1->rtwt += t2->rtwt + 1;
00169   p_stack[y] = t1;
00170   p_stack[x] = p_stack[x+1];
00171 }

void splay int    at,
struct tree_node **    p_stack
 

Definition at line 184 of file util.c.

References tree_node::lft, rotate_left(), rotate_right(), and tree_node::rt.

Referenced by Insert_and_Balance(), Lookup_Delete_Insert(), and ref_tree().

00185 {
00186   int x, px, gx;
00187 
00188   x = at;
00189   px = at-1;
00190   gx = at-2;
00191  
00192   /* 'at' is a left child */
00193   if (p_stack[x] == p_stack[px]->lft)
00194     {
00195       if (gx == 0)   /* zig */
00196         rotate_right(1, p_stack);
00197       else if (p_stack[px] == p_stack[gx]->lft){   /* zig-zig */
00198         rotate_right(gx, p_stack);
00199         rotate_right(gx, p_stack);
00200       }
00201       else
00202         {                               /* zig-zag */
00203           rotate_right(px, p_stack);
00204           rotate_left(gx, p_stack);
00205         }
00206     }
00207   /* 'at' is a right child */
00208   else if (gx == 0)                              /* zig */
00209     rotate_left(1, p_stack);
00210   else if (p_stack[px] == p_stack[gx]->rt)
00211     {         /* zig-zig */
00212       rotate_left(gx, p_stack);
00213       rotate_left(gx, p_stack);
00214     }
00215   else
00216     {                                   /* zig-zag */
00217       rotate_left(px, p_stack);
00218       rotate_right(gx, p_stack);
00219     }
00220 }

void UHT_Add_to_free_list struct hash_table   free_ptr
 

Definition at line 87 of file util.c.

References hash_table::nxt.

Referenced by hash_clean_fa(), hash_clean_sa(), unk_hash_del_fa(), and unk_hash_del_sa().

00088 {
00089   free_ptr->nxt = head_free_list;
00090   head_free_list = free_ptr;
00091 }

struct hash_table* UHT_Get_from_free_list void   
 

Definition at line 94 of file util.c.

References hash_table::nxt.

Referenced by unk_hash_add_fa(), and unk_hash_add_sa().

00096 {
00097   struct hash_table *free_ptr;
00098 
00099   if (head_free_list == NULL)
00100     return NULL;
00101   else
00102     {
00103       free_ptr = head_free_list;
00104       head_free_list = head_free_list->nxt;
00105       return free_ptr;
00106     }
00107 }


Variable Documentation

struct hash_table* head_free_list [static]
 

Definition at line 84 of file util.c.



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214