/* ----------------------------------------------------------------------------- Prints a table. Returns: (int) 1 if table is output as requested 0 if memory for sorted table could not be allocated. ----------------------------------------------------------------------------- */ bool HashTable::printSorted(FILE *fp) const { ListObject **OutTab; ListObject *obj; int i; int cnt = countObjects(); OutTab = getLinearList(); if (OutTab==NULL) return false; sort(OutTab); printHeading(fp); for (i = 0; i < cnt; i++) { obj = OutTab[i]; fprintf(fp, "%3d ", i); if (obj) obj->print(fp); else fputs("????", fp); fputs("\n",fp); } delete[] OutTab; return true; }
int HashTable::countObjects() const { int i,j; int cnt; ListObject *obj; for (cnt = j = i = 0; i < sz; i++) { for (obj = tbl[i]; obj; obj = obj->getNext()) cnt++; } return cnt; }
ListObject *HashTable::find(ListObject *item) const { ListObject *p; ListObject *s; int ii = 0; s = *getChain(item); for (p = *getChain(item); p && item->cmp(p); p = p->getNext()) { if (p==s) if (ii > 0) throw "Stuck in loop."; else ii++; } return p; }
bool HashTable::printUnsorted(FILE *fp) const { ListObject *obj; int i, j; printHeading(fp); for (j = i = 0; j < sz; j++) { for (obj = tbl[j]; obj; obj = obj->getNext()) { fprintf(fp, "%3d ", i); if (obj) obj->print(fp); else fputs("?????", fp); fprintf(fp, "\n"); i++; } } return true; }
// Example socket reader // Wait for receiving SimpleObject and ListObject void runAS_Socket(int port=8000, bool print=true) { int sock=(int)(new TCPReceiver(port))->connect(); if (sock==SOCKET_ERROR) return; BinarySocketReader bsr(sock); // Receive SimpleObject SimpleObject *so; if(AS_FAILED(bsr.read((ISerializable**)&so))) std::cout << "Error at receiving SimpleObject" << std::endl; // Receive List ListObject *lo; if(AS_FAILED(bsr.read((ISerializable**)&lo))) std::cout << "Error at receiving ListObject" << std::endl; std::cout << "Sucessfull receive of SimpleObject and ListObject" << std::endl; if (print) { so->print(); lo->print(); } }