⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tuple.c

📁 压缩包里面的都是精致的基本C语言小程序
💻 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;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -