public function doesNotEqualMapWithDifferentContents() { $other = new HashTable(); $this->map->put(new String('color'), new String('blue')); $other->put(new String('color'), new String('yellow')); $this->assertFalse($this->map->equals($other)); }
function Main() { $hash = new HashTable(); echo "Primeiro teste: Adicionar elementos<br /><br />"; $hash->AddItem("Nome", "Regis"); $hash->AddItem("Sobrenome", "Sebastiani"); echo "Segundo teste: Verificar se existem elementos<br /><br />"; if ($hash->ContainsKey("Sobrenome")) { echo "Tem Sobrenome<br /><br />"; } else { echo "N? tem Sobrenome<br /><br />"; } if ($hash->ContainsKey("Endere?")) { echo "Tem Endere?<br /><br />"; } else { echo "N? tem Endere?<br /><br />"; } if ($hash->ContainsValue("Regis")) { echo "Tem o valor Regis<br /><br />"; } else { echo "N? tem o valor Regis<br /><br />"; } if ($hash->ContainsValue("teste")) { echo "Tem o valor teste<br /><br />"; } else { echo "N? tem o valor teste<br /><br />"; } echo "Terceiro teste: Recuperando um valor<br /><br />"; echo $hash->getValue("Nome") . "<br /><br />"; echo "Quarto teste: Gerando XML<br /><br />"; echo $hash->ToXML(); }
function Main() { $dados = new HashTable(); switch ($_POST['tipo']) { case "exames": $rels = fntMostraRelacoesExame(); $dados->AddItem("relacoes", $rels); break; } echo $dados->ToXML(); }
function Main() { header('Content-Type: text/html; charset=iso-8859-1'); $ht = new HashTable(); $e = new Exame(); $retorno = ""; if ($_POST['context'] == 'N') { $ht->AddItem("imgs", $e->ListaArquivosExame($_SESSION['caso'], $_SESSION['exame'], "img")); $ht->AddItem("docs", $e->ListaArquivosExame($_SESSION['caso'], $_SESSION['exame'], "doc")); $retorno = $ht->ToXML(); } else { $c = new Conteudo(); $retorno = $c->Lista($_SESSION['caso']); } echo Comuns::Idioma($retorno); }
static function __static() { self::$iterate = newinstance('Iterator', array(), '{ private $i= 0, $v, $b; public function on($v) { $self= new self(); $self->v= $v; return $self; } public function current() { return new Pair($this->b[0], $this->b[1]); } public function key() { return $this->i; } public function next() { $this->b= next($this->v); $this->i++; } public function rewind() { reset($this->v); $this->b= current($this->v); $this->i= 0; } public function valid() { return $this->b !== FALSE; } }'); }
public function hashTableRemoveElement() { $c = new HashTable(); $c->put(new String('hello'), new String('world')); $this->assertTrue(isset($c[new String('hello')])); unset($c[new String('hello')]); $this->assertFalse(isset($c[new String('hello')])); }
$this->buckets[$index] = $newNode; // 保存新节点 } public function find($key) { $index = $this->hashfunc($key); $current = $this->buckets[$index]; var_dump($current); while (isset($current)) { // 遍历当前链表 if ($current->key == $key) { // 比较当前节点的关键字 echo $key; return $current->value; // 查询成功 } $current = $current->nextNode; // 比较下一个节点 // var_dump($current); } return NULL; // 查询失败 } } $ht = new HashTable(); $ht->insert('key1', 'value1'); $ht->insert('key12', 'value12'); // 把$current的值覆盖 重新赋值 echo $ht->find('key1'); echo '<br/>'; echo $ht->find('key12');
function Test() { $t = new HashTable(); $text = "YEAR OF GLAD. I am seated in an office, surrounded by heads and bodies. My posture is consciously congruent to the shape of my hard chair. This is a cold room in University Administration, wood-walled, Remington-hung, double-windowed against the November heat, insulated from Administrative sounds by the reception area outside, at which Uncle Charles, Mr. deLint and I were lately received."; $arr = explode(" ", $text); foreach ($arr as $item) { $item = (string) $item; } for ($i = 0; $i < sizeof($arr); $i++) { $t->set($arr[$i], $i); } $res = array(); foreach ($arr as $item) { array_push($res, $t->get($item)); } print_r($res); for ($i = 0; $i < 10; $i++) { $t->remove($arr[$i]); } foreach ($arr as $item) { array_push($res, $t->get($item)); } print_r($res); }
public function MontaTelaExibicao($organizador, $tipo, $chavemostrar, $codcontref) { $html = ""; $htcont = new HashTable(); if ($organizador == "raiz") { // Se for a raiz, exibo os objetivos. $objetivos = new Objetivo(); $objetivos->setCodcaso($_SESSION['casores']); $lista = $objetivos->ListaRecordSet(); if ($lista) { $html = '<ul class="objetivos-caso">'; foreach ($lista as $objetivo) { $html .= '<li>' . $objetivo->Descricao . '</li>'; } $html .= '</ul>'; $htcont->AddItem("conteudo", $html); } else { $htcont->AddItem("conteudo", "@lng[Não foi possível recuperar o conteudo. Detalhes:] " . $objetivos->getErro()); } $htcont->AddItem("titulosecao", "@lng[Objetivos do caso]"); $htcont->AddItem("chave", $chavemostrar); $htcont->AddItem("menu", $this->BuscaMenusItem($tipo)); $htcont->AddItem("saibamais", $this->BuscaDadosSaibaMais($chavemostrar)); } else { if ($organizador == "cont") { //Log::RegistraLog("Organizador enviado: " . $organizador); switch ($tipo) { case 'an': $htcont = $this->RenderAnamnese(1); if ($htcont) { $htcont->AddItem("chave", $chavemostrar); } else { $htcont = new HashTable(); $htcont->AddItem("conteudo", "@lng[Não foi possível recuperar o conteudo. Detalhes:] " . $this->getErro()); } break; case 'aninv': $htcont = $this->RenderAnamnese(2); if ($htcont) { $htcont->AddItem("chave", $chavemostrar); } else { $htcont = new HashTable(); $htcont->AddItem("conteudo", "@lng[Não foi possível recuperar o conteúdo. Detalhes:] " . $this->getErro()); } break; case 'exfis': $htcont = $this->RenderExameFisico(); if ($htcont) { $htcont->AddItem("chave", $chavemostrar); } break; case "optex": $htcont = $this->renderPadrao('optex telaexibicao'); break; case "resex": $htcont = $this->renderPadrao('resex telaexibicao'); break; case "diag": $htcont = $this->renderPadrao('diag telaexibicao'); break; case "trat": $htcont = $this->renderPadrao('trat telaexibicao'); break; case "des": $htcont = $this->renderPadrao('des telaexibicao'); break; case 'html': $htcont = $this->renderHTML($codcontref); break; case 'img': $htcont = $this->renderPadrao('img telaexibicao'); break; case 'vid': $htcont = $this->renderPadrao('vid telaexibicao'); break; case 'aud': $htcont = $this->renderPadrao('aud telaexibicao'); break; case "perg": $htcont = $this->renderPadrao('perg telaexibicao'); break; case "grupo-perg": $htcont = $this->renderPadrao('grupo-perg telaexibicao'); break; } $htcont->AddItem("saibamais", $this->BuscaDadosSaibaMais($chavemostrar)); } else { if ($organizador == "agr") { $htcont->AddItem("conteudo", "Aguarde"); } } } return $htcont; }
/** * Save PHPExcel to file * * @param string $pFileName * @throws Exception */ public function save($pFilename = null) { if (!is_null($this->_spreadSheet)) { // garbage collect $this->_spreadSheet->garbageCollect(); // If $pFilename is php://output or php://stdout, make it a temporary file... $originalFilename = $pFilename; if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { $pFilename = @tempnam('./', 'phpxltmp'); if ($pFilename == '') { $pFilename = $originalFilename; } } $saveDateReturnType = Calculation_Functions::getReturnDateType(); Calculation_Functions::setReturnDateType(Calculation_Functions::RETURNDATE_EXCEL); // Create string lookup table $this->_stringTable = array(); for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++$i) { $this->_stringTable = $this->getWriterPart('StringTable')->createStringTable($this->_spreadSheet->getSheet($i), $this->_stringTable); } // Create styles dictionaries $this->_stylesConditionalHashTable->addFromSource($this->getWriterPart('Style')->allConditionalStyles($this->_spreadSheet)); $this->_fillHashTable->addFromSource($this->getWriterPart('Style')->allFills($this->_spreadSheet)); $this->_fontHashTable->addFromSource($this->getWriterPart('Style')->allFonts($this->_spreadSheet)); $this->_bordersHashTable->addFromSource($this->getWriterPart('Style')->allBorders($this->_spreadSheet)); $this->_numFmtHashTable->addFromSource($this->getWriterPart('Style')->allNumberFormats($this->_spreadSheet)); // Create drawing dictionary $this->_drawingHashTable->addFromSource($this->getWriterPart('Drawing')->allDrawings($this->_spreadSheet)); // Create new ZIP file and open it for writing $objZip = new ZipArchive(); // Try opening the ZIP file if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) { if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) { throw new Exception("Could not open " . $pFilename . " for writing."); } } // Add [Content_Types].xml to ZIP file $objZip->addFromString('[Content_Types].xml', $this->getWriterPart('ContentTypes')->writeContentTypes($this->_spreadSheet)); // Add relationships to ZIP file $objZip->addFromString('_rels/.rels', $this->getWriterPart('Rels')->writeRelationships($this->_spreadSheet)); $objZip->addFromString('xl/_rels/workbook.xml.rels', $this->getWriterPart('Rels')->writeWorkbookRelationships($this->_spreadSheet)); // Add document properties to ZIP file $objZip->addFromString('docProps/app.xml', $this->getWriterPart('DocProps')->writeDocPropsApp($this->_spreadSheet)); $objZip->addFromString('docProps/core.xml', $this->getWriterPart('DocProps')->writeDocPropsCore($this->_spreadSheet)); // Add theme to ZIP file $objZip->addFromString('xl/theme/theme1.xml', $this->getWriterPart('Theme')->writeTheme($this->_spreadSheet)); // Add string table to ZIP file $objZip->addFromString('xl/sharedStrings.xml', $this->getWriterPart('StringTable')->writeStringTable($this->_stringTable)); // Add styles to ZIP file $objZip->addFromString('xl/styles.xml', $this->getWriterPart('Style')->writeStyles($this->_spreadSheet)); // Add workbook to ZIP file $objZip->addFromString('xl/workbook.xml', $this->getWriterPart('Workbook')->writeWorkbook($this->_spreadSheet)); // Add worksheets for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++$i) { $objZip->addFromString('xl/worksheets/sheet' . ($i + 1) . '.xml', $this->getWriterPart('Worksheet')->writeWorksheet($this->_spreadSheet->getSheet($i), $this->_stringTable)); } // Add worksheet relationships (drawings, ...) for ($i = 0; $i < $this->_spreadSheet->getSheetCount(); ++$i) { // Add relationships $objZip->addFromString('xl/worksheets/_rels/sheet' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeWorksheetRelationships($this->_spreadSheet->getSheet($i), $i + 1)); // Add drawing relationship parts if ($this->_spreadSheet->getSheet($i)->getDrawingCollection()->count() > 0) { // Drawing relationships $objZip->addFromString('xl/drawings/_rels/drawing' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeDrawingRelationships($this->_spreadSheet->getSheet($i))); // Drawings $objZip->addFromString('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->_spreadSheet->getSheet($i))); } // Add comment relationship parts if (count($this->_spreadSheet->getSheet($i)->getComments()) > 0) { // VML Comments $objZip->addFromString('xl/drawings/vmlDrawing' . ($i + 1) . '.vml', $this->getWriterPart('Comments')->writeVMLComments($this->_spreadSheet->getSheet($i))); // Comments $objZip->addFromString('xl/comments' . ($i + 1) . '.xml', $this->getWriterPart('Comments')->writeComments($this->_spreadSheet->getSheet($i))); } // Add header/footer relationship parts if (count($this->_spreadSheet->getSheet($i)->getHeaderFooter()->getImages()) > 0) { // VML Drawings $objZip->addFromString('xl/drawings/vmlDrawingHF' . ($i + 1) . '.vml', $this->getWriterPart('Drawing')->writeVMLHeaderFooterImages($this->_spreadSheet->getSheet($i))); // VML Drawing relationships $objZip->addFromString('xl/drawings/_rels/vmlDrawingHF' . ($i + 1) . '.vml.rels', $this->getWriterPart('Rels')->writeHeaderFooterDrawingRelationships($this->_spreadSheet->getSheet($i))); // Media foreach ($this->_spreadSheet->getSheet($i)->getHeaderFooter()->getImages() as $image) { $objZip->addFromString('xl/media/' . $image->getIndexedFilename(), file_get_contents($image->getPath())); } } } // Add media for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) { if ($this->getDrawingHashTable()->getByIndex($i) instanceof Worksheet_Drawing) { $imageContents = null; $imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath(); if (strpos($imagePath, 'zip://') !== false) { $imagePath = substr($imagePath, 6); $imagePathSplitted = explode('#', $imagePath); $imageZip = new ZipArchive(); $imageZip->open($imagePathSplitted[0]); $imageContents = $imageZip->getFromName($imagePathSplitted[1]); $imageZip->close(); unset($imageZip); } else { $imageContents = file_get_contents($imagePath); } $objZip->addFromString('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); } else { if ($this->getDrawingHashTable()->getByIndex($i) instanceof Worksheet_MemoryDrawing) { ob_start(); call_user_func($this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(), $this->getDrawingHashTable()->getByIndex($i)->getImageResource()); $imageContents = ob_get_contents(); ob_end_clean(); $objZip->addFromString('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); } } } Calculation_Functions::setReturnDateType($saveDateReturnType); // Close file if ($objZip->close() === false) { throw new Exception("Could not close zip file {$pFilename}."); } // If a temporary file was used, copy it to the correct file stream if ($originalFilename != $pFilename) { if (copy($pFilename, $originalFilename) === false) { throw new Exception("Could not copy temporary zip file {$pFilename} to {$originalFilename}."); } @unlink($pFilename); } } else { throw new Exception("PHPExcel object unassigned."); } }
} return null; } private function hashFunc($key) { $strLen = strlen($key); $hashval = 0; for ($i = 0; $i < $strLen; $i++) { $hashval += ord($key[$i]); } return $hashval % $this->size; } } class HashNode { public $key; public $value; public $nextNode; public function __construct($key, $value, $nextNode = null) { $this->key = $key; $this->value = $value; $this->nextNode = $nextNode; } } $hashTable = new HashTable(); $hashTable->insert('key1', 'value1'); $hashTable->insert('key12', 'value2'); echo $hashTable->find('key1'); echo ' '; echo $hashTable->find('key12');
function TrataDadosConteudosDlg() { $dados = new HashTable(); if (isset($_SESSION['caso']) && $_SESSION['caso'] != 0) { $c = new Conteudo(); if ($_POST['r'] != "") { $codconteudo = base64_decode($_POST['r']); $_SESSION['conteudo'] = $codconteudo; $c->Carrega($_SESSION['caso'], $codconteudo); $dados->AddItem("txtTexto", $c->getTexto()); $dados->AddItem("txtDescricao", $c->getDescricao()); } else { $_SESSION['conteudo'] = 0; $dados->AddItem("txtTexto", ""); $dados->AddItem("txtDescricao", ""); } return $dados->ToXML(); } else { return "@lng[Erro ao localizar o caso de estudo]"; } }
unset($this->HashTable[$bucket][$x]); } } /** everything is OK **/ return 0; } public function search($string) { $resultArray = array(); $bucket = $this->generate_bucket($string); if (is_null($this->HashTable[$bucket])) { return -1; } else { if (is_array($this->HashTable[$bucket])) { for ($x = 0; $x <= sizeof($this->HashTable[$bucket]); $x++) { if (strcmp($this->HashTable[$bucket][$x]['string'], $string) == 0) { array_push($resultArray, $this->HashTable[$bucket][$x]); } } } else { array_push($resultArray, $this->HashTable[$bucket]); } } return $resultArray; } } $hash = new HashTable(16); // $arr = array('nombre' => "jorge niedbalski"); $hash->add("astroza", $arr); $hash->add("astrozas", $arr); print_r($hash->search("astrozas"));
public function RetornaConfigs($tipo, $item) { $sql .= "SELECT conf.CodConfig, conf.Prefixo, conf.Nome, val.Valor "; $sql .= "FROM mescasomontagemconfigs conf "; $sql .= "LEFT OUTER JOIN mescasomontagemvalconfigs val "; $sql .= "\t\t\t ON val.CodConfig = conf.CodConfig "; $sql .= "\t\t\tAND val.CodCaso = :pCodCaso "; $sql .= "\t\t\tAND val.CodMontagem = 1 "; $sql .= "\t\t\tAND val.Chave = :pChave "; $sql .= "WHERE ((conf.Grupo & (SELECT CodBinario FROM mestipoitem WHERE Codigo = :pTipoItem)) > 0);"; /* $sql = "SELECT val.CodConfig, val.Valor, conf.Prefixo "; $sql .= "FROM mescasomontagemvalconfigs val "; $sql .= "INNER JOIN mescasomontagemconfigs conf "; $sql .= " ON conf.CodConfig = val.CodConfig "; $sql .= "WHERE CodCaso = :pCodCaso "; $sql .= " AND CodMontagem = 1 "; $sql .= " AND Chave = :pChave"; */ $cnn = Conexao2::getInstance(); $cmd = $cnn->prepare($sql); $cmd->bindParam(":pCodCaso", $this->codcaso, PDO::PARAM_INT); $cmd->bindParam(":pChave", $item, PDO::PARAM_STR); $cmd->bindParam(":pTipoItem", $tipo, PDO::FETCH_OBJ); $cmd->execute(); if ($cmd->errorCode() == Comuns::QUERY_OK) { if ($cmd->rowCount() > 0) { $hash = new HashTable(); $arrconfs = ""; while ($item = $cmd->fetch(PDO::FETCH_OBJ)) { $hash->AddItem($item->Prefixo . "Config_" . $item->CodConfig, $item->Valor); $arrconfs .= ($arrconfs != '' ? ';' : '') . $item->CodConfig; } $hash->AddItem("ArrConfs", $arrconfs); return $hash->ToXML(); } else { $this->msg_erro = "@lng[Nada cadastrado]"; return false; } } else { $msg = $cmd->errorInfo(); $this->msg_erro = $msg[2]; return false; } }
private function BuscaConteudoDesfecho($prefixo, $chave, $tipocaso) { $hash = new HashTable(); if ($tipocaso == 1) { $sql = "SELECT Titulo, Desfecho FROM mescasodesfecho "; $sql .= "WHERE CodCaso = :pCodCaso;"; } else { $sql = "SELECT Titulo, Desfecho FROM mescasodesfecho "; $sql .= "WHERE CodCaso = :pCodCaso;"; } $cnn = Conexao2::getInstance(); $cmd = $cnn->prepare($sql); $cmd->bindParam(":pCodCaso", $this->codigo, PDO::PARAM_INT); $cmd->execute(); if ($cmd->errorCode() == Comuns::QUERY_OK) { if ($cmd->rowCount() > 0) { $reg = $cmd->fetch(PDO::FETCH_OBJ); $titulo = $reg->Titulo; $conteudo = $reg->Desfecho; } else { $titulo = ""; $conteudo = "@lng[Nenhum registro encontrado]"; } } else { $msg = $cmd->errorInfo(); $this->msg_erro = $msg[2]; $titulo = "@lng[Erro defecho]"; $conteudo = "Erro: " . $this->msg_erro; } $comandos = $this->MontaAcoesVisualizacaoCaso($prefixo, $tipocaso, $chave); $hash->AddItem("titulosecao", $titulo); $hash->AddItem("conteudo", $conteudo); $hash->AddItem("menu", $comandos); $hash->AddItem("Obrigatorio", false); return $hash; }
/** * Makes a WebQueueBundle with the provided parameters * * @param string $dir_name folder name used by this WebQueueBundle * @param int $filter_size size of each partition in the page exists * BloomFilterBundle * @param int $num_urls_ram number of entries in ram for the priority queue * @param string $min_or_max when the priority queue maintain the heap * property with respect to the least or the largest weight */ function __construct($dir_name, $filter_size, $num_urls_ram, $min_or_max) { $this->dir_name = $dir_name; $this->filter_size = $filter_size; $this->num_urls_ram = $num_urls_ram; $this->min_or_max = $min_or_max; if (!file_exists($this->dir_name)) { mkdir($this->dir_name); } /* if we are resuming a crawl we discard the old priority queue and associated hash table and archive new queue data will be read in from any existing schedule */ // set up the priority queue... stores (hash(url), weight) pairs. $this->to_crawl_queue = new PriorityQueue($dir_name . "/queue.dat", $num_urls_ram, self::HASH_KEY_SIZE, $min_or_max, $this, 0); /* set up the hash table... stores (hash(url), offset into url archive, index in priority queue) triples. */ /*to ensure we can always insert into table, because of how deletions work we will periodically want to rebuild our table we will also want to give a little more than the usual twice the number we want to insert slack */ $this->to_crawl_table = $this->constructHashTable($dir_name . "/hash_table.dat", 8 * $num_urls_ram); /* set up url archive, used to store the full text of the urls which are on the priority queue */ $url_archive_name = $dir_name . "/url_archive" . NonCompressor::fileExtension(); if (file_exists($url_archive_name)) { unlink($url_archive_name); } $this->to_crawl_archive = new WebArchive($url_archive_name, new NonCompressor(), false, true); //timestamp for url filters (so can delete if get too old) if (!file_exists($dir_name . "/url_timestamp.txt")) { file_put_contents($dir_name . "/url_timestamp.txt", time()); } //filter bundle to check if we have already visited a URL $this->url_exists_filter_bundle = new BloomFilterBundle($dir_name . "/UrlExistsFilterBundle", $filter_size); //timestamp for robot filters (so can delete if get too old) if (!file_exists($dir_name . "/robot_timestamp.txt")) { file_put_contents($dir_name . "/robot_timestamp.txt", time()); } //filter to check if we have already have a copy of a robot.txt file if (file_exists($dir_name . "/got_robottxt.ftr")) { $this->got_robottxt_filter = BloomFilterFile::load($dir_name . "/got_robottxt.ftr"); } else { $this->got_robottxt_filter = new BloomFilterFile($dir_name . "/got_robottxt.ftr", $filter_size); } /* Hash table containing DNS cache this is cleared whenever robot filters cleared */ if (file_exists($dir_name . "/dns_table.dat")) { $this->dns_table = HashTable::load($dir_name . "/dns_table.dat"); } else { $this->dns_table = new HashTable($dir_name . "/dns_table.dat", 4 * $num_urls_ram, self::HASH_KEY_SIZE, self::IP_SIZE); } //set up storage for robots.txt info $robot_archive_name = $dir_name . "/robot_archive" . NonCompressor::fileExtension(); $this->robot_archive = new WebArchive($robot_archive_name, new NonCompressor(), false, true); if (file_exists($dir_name . "/robot.dat")) { $this->robot_table = HashTable::load($dir_name . "/robot.dat"); } else { $this->robot_table = new HashTable($dir_name . "/robot.dat", 16 * $num_urls_ram, self::HASH_KEY_SIZE, self::INT_SIZE); } //filter to check for and determine crawl delay if (file_exists($dir_name . "/crawl_delay.ftr")) { $this->crawl_delay_filter = BloomFilterFile::load($dir_name . "/crawl_delay.ftr"); } else { $this->crawl_delay_filter = new BloomFilterFile($dir_name . "/crawl_delay.ftr", $filter_size); } //Initialize B-Tree for storing cache page validation data $this->etag_btree = new BTree($dir_name . '/EtagExpiresTree'); $this->notify_buffer = array(); }
<?php require_once "HashTable.php"; $h = new HashTable(); $h->addItem("foo", "bar"); $h->addItem("chicken", "coop"); $h->addItem("oof", "rab"); echo $h->getItem("chicken") . "\n"; echo $h->getItem("foo") . "\n"; echo $h->getItem("oof") . "\n";
function BuscaRespostaAgrupadores($codcaso, $chave) { $hash = new HashTable(); $explicacoes = ""; foreach ($_POST as $campo => $valor) { if (substr($campo, 0, 3) == "rdo") { $detalhes = split("_", $campo); $pergunta = $detalhes[1]; $p = new Pergunta(); $acertou = VerificaAcerto($pergunta, $_POST[$campo]); $hash->AddItem($pergunta, $acertou === true ? 's' : 'n'); $p->Carregar($pergunta); $alternativas = $p->getAlternativas(); foreach ($alternativas as $alt) { if (!is_null($alt->getExplicacao()) && strip_tags($alt->getExplicacao()) != "") { $explicacoes .= '<div class="explicacao">' . $alt->getExplicacao() . '</div>'; } } if (!is_null($p->getTextoExplicacaoGeral())) { $explicacoes = '<div class="explicacao">' . $p->getTextoExplicacaoGeral() . '</div>' . $explicacoes; } } } $retornos = $hash->ToArray(); $certas = 0; $erradas = 0; foreach ($retornos as $chave => $item) { if ($item == 's') { $certas++; } else { $erradas++; } $imgs .= ($imgs != "" ? "," : "") . $chave . '_' . $item; } $conteudo = "<p>@lng[Você] "; if ($certas > 0 && $erradas > 0) { $conteudo .= "@lng[acertou] " . $certas; } else { if ($certas > 0 && $erradas == 0) { $conteudo .= "@lng[acertou todas as questões]"; } } if ($certas > 0 && $erradas > 0) { $conteudo .= " @lng[e errou] " . $erradas; } else { if ($certas == 0 && $erradas > 0) { $conteudo .= " @lng[errou as] " . $erradas . " @lng[questões.]"; } } return '<texto>' . $conteudo . '</p><p>' . $explicacoes . '</p></texto><imgs>' . $imgs . '</imgs>'; }