1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2003 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <wtf/Assertions.h>
33 static inline bool keysMatch(const UChar
*c
, unsigned len
, const char *s
)
35 const char* end
= s
+ len
;
36 for (; s
!= end
; c
++, s
++)
37 if (c
->uc
!= (unsigned char)*s
)
42 static inline const HashEntry
* findEntry(const struct HashTable
*table
, unsigned int hash
,
43 const UChar
*c
, unsigned int len
)
46 if (table
->type
!= 2) {
47 fprintf(stderr
, "KJS: Unknown hash table version.\n");
51 ASSERT(table
->hashSize
!= 0);
53 hash
%= table
->hashSize
;
55 const HashEntry
*e
= &table
->entries
[hash
];
63 if (keysMatch(c
, len
, e
->s
))
72 const HashEntry
* Lookup::findEntry(const struct HashTable
*table
,
75 const HashEntry
* entry
= ::findEntry(table
, s
.ustring().rep()->hash(), s
.data(), s
.size());
79 int Lookup::find(const struct HashTable
*table
,
80 const UChar
*c
, unsigned int len
)
82 const HashEntry
*entry
= ::findEntry(table
, UString::Rep::computeHash(c
, len
), c
, len
);
88 int Lookup::find(const struct HashTable
*table
, const Identifier
&s
)
90 //printf("looking for:%s\n", s.ascii());
91 const HashEntry
*entry
= ::findEntry(table
, s
.ustring().rep()->hash(), s
.data(), s
.size());