예제 #1
0
int main()
{
	HashTable hash_table;
	hash_table.insert(1, 20);
	hash_table.insert(2, 70);
	hash_table.insert(42, 80);
	hash_table.insert(4, 25);
	hash_table.insert(12, 44);
	hash_table.insert(14, 32);
	hash_table.insert(17, 11);
	hash_table.insert(13, 78);
	hash_table.insert(37, 97);
	
	hash_table.display();

	DataItem item = hash_table.search(37);

	if (item != HashTable::emptyItem && item != HashTable::dummyItem)
		cout << "Element found: " << item.getData() << endl;
	else
		cout << "Element not found" << endl;

	hash_table.remove(37);
	item = hash_table.search(37);

	if (item != HashTable::emptyItem && item != HashTable::dummyItem)
		cout << "Element found: " << item.getData() << endl;
	else
		cout << "Element not found" << endl;

	hash_table.display();
	return 0;
}
예제 #2
0
PyObject* DataRecord::getData(int verbose)
{
	PyObject*p = PyDict_New();

	PyObject* k1 = Py_BuildValue("s", "category");
	PyObject* v1 = Py_BuildValue("H", m_pCategory->m_id);
	PyDict_SetItem(p, k1, v1);
	Py_DECREF(k1);
	Py_DECREF(v1);

	PyObject* k2 = Py_BuildValue("s", "len");
	PyObject* v2 = Py_BuildValue("l", m_nLength);
	PyDict_SetItem(p, k2, v2);
	Py_DECREF(k2);
	Py_DECREF(v2);

    char hexcrc[9];
    sprintf(hexcrc, "%08X", m_nCrc);
	PyObject* k3 = Py_BuildValue("s", "crc");
	PyObject* v3 = Py_BuildValue("s", hexcrc);
	PyDict_SetItem(p, k3, v3);
	Py_DECREF(k3);
	Py_DECREF(v3);

	PyObject* k4 = Py_BuildValue("s", "ts");
	PyObject* v4 = Py_BuildValue("l", m_nTimestamp);
	PyDict_SetItem(p, k4, v4);
	Py_DECREF(k4);
	Py_DECREF(v4);

    if (m_bFormatOK)
    {
        // go through all present data items in this record
        std::list<DataItem*>::iterator it;
        for ( it=m_lDataItems.begin() ; it != m_lDataItems.end(); it++ )
        {
            DataItem* di = (DataItem*)(*it);
            if (di)
            {
                PyObject* v1 = di->getData(verbose);
                char tmp[20];
                snprintf(tmp, 20, "I%s", di->m_pDescription->m_strID.c_str());
                PyObject* k1 = Py_BuildValue("s", tmp);
                PyDict_SetItem(p, k1, v1);
                Py_DECREF(k1);
                Py_DECREF(v1);
            }
        }
    }

  return p;
}
예제 #3
0
PyObject* DataRecord::getData()
{
	UAP* pUAP = m_pCategory->getUAP(m_pFSPECData, m_nFSPECLength);
	PyObject*p = PyDict_New();

	PyObject* k1 = Py_BuildValue("s", "category");
	PyObject* v1 = Py_BuildValue("H", m_pCategory->m_id);
	PyDict_SetItem(p, k1, v1);
	Py_DECREF(k1);
	Py_DECREF(v1);

	PyObject* k2 = Py_BuildValue("s", "len");
	PyObject* v2 = Py_BuildValue("l", m_nLength);
	PyDict_SetItem(p, k2, v2);
	Py_DECREF(k2);
	Py_DECREF(v2);

    char hexcrc[9];
    sprintf(hexcrc, "%08X", m_nCrc);
	PyObject* k3 = Py_BuildValue("s", "crc");
	PyObject* v3 = Py_BuildValue("s", hexcrc);
	PyDict_SetItem(p, k3, v3);
	Py_DECREF(k3);
	Py_DECREF(v3);

	PyObject* k4 = Py_BuildValue("s", "ts");
	PyObject* v4 = Py_BuildValue("l", m_nTimestamp);
	PyDict_SetItem(p, k4, v4);
	Py_DECREF(k4);
	Py_DECREF(v4);

	if (!pUAP)
	{
		Tracer::Error("UAP for CAT%03d not found!", m_pCategory->m_id);
	}
	else
	{
		// go through all present data items in this record
		std::list<DataItem*>::iterator it;
		for ( it=m_lDataItems.begin() ; it != m_lDataItems.end(); it++ )
		{
			DataItem* di = (DataItem*)(*it);
			if (di)
			{
				PyObject* v1 = di->getData();
				char tmp[20];
				sprintf(tmp, "I%s", di->m_pDescription->m_strID.c_str());
                PyObject* k1 = Py_BuildValue("s", tmp);
				PyDict_SetItem(p, k1, v1);
                Py_DECREF(k1);
				Py_DECREF(v1);
			}
		}
	}

  if (!m_bFormatOK)
  {
    // TODO err
  }

  return p;
}
예제 #4
0
fulliautomatix_data* DataRecord::getData(int byteoffset)
{
  fulliautomatix_data *firstData = NULL, *lastData=NULL;
  int endOffset = byteoffset+m_nLength;

  char tmp[64];
  sprintf(tmp, "Data Record %d - %ld bytes", m_nID, m_nLength);

  firstData = lastData = newDataTree(lastData, byteoffset, m_nLength, tmp);

  UAP* pUAP = m_pCategory->getUAP(m_pFSPECData, m_nFSPECLength);
  if (!pUAP)
  {
    Tracer::Error("UAP for CAT%03d not found!", m_pCategory->m_id);
    firstData->err = 2;
  }
  else
  {
    lastData = newDataTree(lastData, byteoffset, m_nFSPECLength, (char*)"FSPEC");

    // go through all UAPitems items in this record
    std::list<UAPItem*>::iterator uapit;
    for ( uapit=pUAP->m_lUAPItems.begin(); uapit != pUAP->m_lUAPItems.end(); uapit++ )
    {
      UAPItem* uap = (UAPItem*)(*uapit);
      lastData->next = uap->getData(m_pFSPECData, m_nFSPECLength, byteoffset);

      if(lastData->next)
      {
        lastData = lastData->next;
      }
      else
      {
        break;
      }
    }
    byteoffset += m_nFSPECLength;

    lastData = newDataTreeEnd(lastData, byteoffset);

    // go through all present data items in this record
    std::list<DataItem*>::iterator it;
    for ( it=m_lDataItems.begin() ; it != m_lDataItems.end(); it++ )
    {
      DataItem* di = (DataItem*)(*it);
      if (di)
      {
        lastData->next = di->getData(byteoffset);
        while(lastData->next)
        {
          if (lastData->next->err)
          {
            firstData->err = lastData->next->err;
          }
          lastData = lastData->next;
        }
        byteoffset = lastData->bytenr;
      }
    }
  }

  if (!m_bFormatOK)
  {
    firstData->err = 2;
  }

  lastData = newDataTreeEnd(lastData,endOffset);
  return firstData;
}