• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
  • codeimport
  • kdevcppparser
lookup.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 2 -*-
2 /*
3  * This file is part of the KDE libraries
4  * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  */
21 
22 // adapted to kdevelop by Roberto Raggi <roberto@kdevelop.org>
23 
24 #include "lookup.h"
25 
26 #include "debug_utils.h"
27 
28 const HashEntry* Lookup::findEntry(const struct HashTable *table,
29  const QChar *c, unsigned int len)
30 {
31  if (table->type != 2) {
32  uDebug() << "KJS: Unknown hash table version";
33  return 0;
34  }
35  char *ascii = new char[len+1];
36  unsigned int i;
37  for (i = 0; i < len; ++i, ++c) {
38  if (!c->row())
39  ascii[i] = c->cell();
40  else
41  break;
42  }
43  ascii[i] = '\0';
44 
45  int h = hash(ascii) % table->hashSize;
46  const HashEntry *e = &table->entries[h];
47 
48  // empty bucket ?
49  if (!e->s) {
50  delete [] ascii;
51  return 0;
52  }
53 
54  do {
55  // compare strings
56  if (strcmp(ascii, e->s) == 0) {
57  delete [] ascii;
58  return e;
59  }
60  // try next bucket
61  e = e->next;
62  } while (e);
63 
64  delete [] ascii;
65  return 0;
66 }
67 
68 const HashEntry* Lookup::findEntry(const struct HashTable *table,
69  const QString &s)
70 {
71  return findEntry(table, s.unicode(), s.length());
72 }
73 
74 int Lookup::find(const struct HashTable *table,
75  const QChar *c, unsigned int len)
76 {
77  const HashEntry *entry = findEntry(table, c, len);
78  if (entry)
79  return entry->value;
80  return -1;
81 }
82 
83 int Lookup::find(const struct HashTable *table, const QString &s)
84 {
85  return find(table, s.unicode(), s.length());
86 }
87 
88 unsigned int Lookup::hash(const QChar *c, unsigned int len)
89 {
90  unsigned int val = 0;
91  // ignoring rower byte
92  for (unsigned int i = 0; i < len; ++i, ++c) {
93  val += c->cell();
94  }
95 
96  return val;
97 }
98 
99 unsigned int Lookup::hash(const QString &key)
100 {
101  return hash(key.unicode(), key.length());
102 }
103 
104 unsigned int Lookup::hash(const char *s)
105 {
106  unsigned int val = 0;
107  while (*s)
108  val += *s++;
109 
110  return val;
111 }
HashTable
A hash table Usually the hashtable is generated by the create_hash_table script, from a ...
Definition: lookup.h:67
lookup.h
Lookup::findEntry
static const HashEntry * findEntry(const struct HashTable *table, const QString &s)
Find an entry in the table, and return the entry This variant gives access to the other attributes of...
Definition: lookup.cpp:68
debug_utils.h
HashEntry::s
const char * s
s is the key (e.g.
Definition: lookup.h:36
HashTable::hashSize
int hashSize
the maximum value for the hash.
Definition: lookup.h:86
Lookup::find
static int find(const struct HashTable *table, const QString &s)
Find an entry in the table, and return its value (i.e.
Definition: lookup.cpp:83
uDebug
#define uDebug()
Definition: debug_utils.h:95
Lookup::hash
static unsigned int hash(const QString &key)
Calculate the hash value for a given key.
Definition: lookup.cpp:99
HashTable::type
int type
type is a version number.
Definition: lookup.h:71
HashEntry
An entry in a hash table.
Definition: lookup.h:32
HashEntry::value
int value
value is the result value (usually an enum value)
Definition: lookup.h:40
HashTable::entries
const HashEntry * entries
pointer to the array of entries Mind that some entries in the array are null (0, 0, 0, 0).
Definition: lookup.h:82
HashEntry::next
const HashEntry * next
next is the pointer to the next entry for the same hash value
Definition: lookup.h:53
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:06:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal