~ubuntu-dev/ubuntu/lucid/mutt/lucid-201002101854

« back to all changes in this revision

Viewing changes to hash.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Berg, Antonio Radici, Christoph Berg
  • Date: 2009-06-20 15:00:50 UTC
  • mfrom: (16.1.1 sid) (16.2.1 experimental)
  • mto: (2.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20090620150050-ta3y92wwef0m5y4t
Tags: 1.5.20-2
[ Antonio Radici ]
* debian/patches/series:
  + upstream/533209-mutt_perror.patch: better error reporting if a mailbox
    cannot be opened (Closes: 533209)
  + upstream/533459-unmailboxes.patch: fixes a segfault with the unmailboxes 
    command (Closes: 533459)
  + upstream/533439-mbox-time.patch: do not corrupt the atime/mtime of 
    mboxes when opened (Closes: 533439)
  + upstream/531430-imapuser.patch: ask the user for the right information
    while logging in on IMAP servers (Closes: 531430)
  + upstream/534543-imap-port.patch: correctly parse the port in an IMAP
    url (Closes: 534543)
  + added the right copyright misc/smime_keys-manpage.patch
  + mutt-patched/sidebar: refreshed
  + mutt-patched/sidebar-{dotted,sorted} added (Closes: 523774)
* debian/control:
  + Debian policy bumped to 3.8.2
* debian/mutt.install and debian/extra/lib/mailto-mutt: 
  + added the firefox mailto handler (Closes: 406850)

[ Christoph Berg ]
* Remove maildir-mtime patch, upstream has a different implementation
  (though with different results; Closes: 533471)
* Use elinks-lite (with an alternative Build-Dependency on elinks) for
  rendering the manual. Thanks to Ahmed El-Mahmoudy for the suggestion.
  (Closes: 533445)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
 
2
 * Copyright (C) 1996-2009 Michael R. Elkins <me@mutt.org>
3
3
 *
4
4
 *     This program is free software; you can redistribute it and/or modify
5
5
 *     it under the terms of the GNU General Public License as published by
23
23
#include <stdlib.h>
24
24
#include <stdio.h>
25
25
#include <string.h>
 
26
#include <ctype.h>
26
27
 
27
28
#include "mutt.h"
28
29
 
29
30
#define SOMEPRIME 149711
30
31
 
31
 
int hash_string (const unsigned char *s, int n)
 
32
static unsigned int hash_string (const unsigned char *s, unsigned int n)
32
33
{
33
 
  int h = 0;
 
34
  unsigned int h = 0;
34
35
 
35
 
#if 0
36
 
  while (*s)
37
 
    h += *s++;
38
 
#else
39
36
  while (*s)
40
37
    h += (h << 7) + *s++;
41
38
  h = (h * SOMEPRIME) % n;
42
 
  h = (h >= 0) ? h : h + n;
43
 
#endif
44
 
 
45
 
  return (h % n);
46
 
}
47
 
 
48
 
HASH *hash_create (int nelem)
 
39
 
 
40
  return h;
 
41
}
 
42
 
 
43
static unsigned int hash_case_string (const unsigned char *s, unsigned int n)
 
44
{
 
45
  unsigned int h = 0;
 
46
 
 
47
  while (*s)
 
48
    h += (h << 7) + tolower (*s++);
 
49
  h = (h * SOMEPRIME) % n;
 
50
 
 
51
  return h;
 
52
}
 
53
 
 
54
HASH *hash_create (int nelem, int lower)
49
55
{
50
56
  HASH *table = safe_malloc (sizeof (HASH));
51
57
  if (nelem == 0)
52
58
    nelem = 2;
53
59
  table->nelem = nelem;
54
60
  table->table = safe_calloc (nelem, sizeof (struct hash_elem *));
 
61
  if (lower)
 
62
  {
 
63
    table->hash_string = hash_case_string;
 
64
    table->cmp_string = mutt_strcasecmp;
 
65
  }
 
66
  else
 
67
  {
 
68
    table->hash_string = hash_string;
 
69
    table->cmp_string = mutt_strcmp;
 
70
  }
55
71
  return table;
56
72
}
57
73
 
63
79
int hash_insert (HASH * table, const char *key, void *data, int allow_dup)
64
80
{
65
81
  struct hash_elem *ptr;
66
 
  int h;
 
82
  unsigned int h;
67
83
 
68
84
  ptr = (struct hash_elem *) safe_malloc (sizeof (struct hash_elem));
69
 
  h = hash_string ((unsigned char *) key, table->nelem);
 
85
  h = table->hash_string ((unsigned char *) key, table->nelem);
70
86
  ptr->key = key;
71
87
  ptr->data = data;
72
88
 
82
98
 
83
99
    for (tmp = table->table[h], last = NULL; tmp; last = tmp, tmp = tmp->next)
84
100
    {
85
 
      r = mutt_strcmp (tmp->key, key);
 
101
      r = table->cmp_string (tmp->key, key);
86
102
      if (r == 0)
87
103
      {
88
104
        FREE (&ptr);
105
121
  struct hash_elem *ptr = table->table[hash];
106
122
  for (; ptr; ptr = ptr->next)
107
123
  {
108
 
    if (mutt_strcmp (key, ptr->key) == 0)
 
124
    if (table->cmp_string (key, ptr->key) == 0)
109
125
      return (ptr->data);
110
126
  }
111
127
  return NULL;
120
136
  while (ptr) 
121
137
  {
122
138
    if ((data == ptr->data || !data)
123
 
        && mutt_strcmp (ptr->key, key) == 0)
 
139
        && table->cmp_string (ptr->key, key) == 0)
124
140
    {
125
141
      *last = ptr->next;
126
142
      if (destroy)