?? tuple.c
字號:
#include <stdio.h>#include "mystdlib.h"#include "error.h"#include "tuple.h"static int flag = 1;struct tuple{ tyVft vft; poly x; poly y;};struct tyVft tupleVft;tuple newTuple (poly x, poly y){ if (flag) { flag--; tupleVft.equals = tupleEquals; tupleVft.getPlist = tupleGetPlist; tupleVft.hashCode = tupleHashCode; tupleVft.toString = tupleToString; } tuple t = checkedMalloc (sizeof (*t)); t->vft = &tupleVft; t->x = x; t->y = y; return t;}poly tupleFirst (tuple t){ return t->x;}poly tupleSecond (tuple t){ return t->y;}int tupleEquals (poly t11, poly t12){ tuple t1 = (tuple)t11; tuple t2 = (tuple)t12; tyEquals eqx = getVft (t1->x)->equals; tyEquals eqy = getVft (t1->y)->equals; return (eqx (t1->x, t2->x) && eqy (t1->y, t2->y));}int tupleEquals2 (tuple t1, tuple t2, tyEquals eqx, tyEquals eqy){ return (eqx (t1->x, t2->x) && eqy (t1->y, t2->y));}str tupleToString (poly t1){ tuple t = (tuple)t1; tyToString strx = getVft (t->x)->toString; tyToString stry = getVft (t->y)->toString; str s1 = newStr ("("); str s2 = strx (t->x); str s3 = newStr (", "); str s4 = stry (t->y); str s5 = newStr (")"); // free all these stuff? return strConcat (s1, strConcat (s2, strConcat (s3, strConcat (s4, s5))));}plist tupleGetPlist (poly t){ exception ("not implemented yet\n"); return 0;}int tupleHashCode (poly t1){ tuple t = (tuple)t1; tyHashCode h1 = getVft (t->x)->hashCode; tyHashCode h2 = getVft (t->y)->hashCode; int i1 = h1 (t->x); int i2 = h2 (t->y); return i1+i2;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -