OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [runtime/] [go-map-range.c] - Blame information for rev 791

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
/* go-map-range.c -- implement a range clause over a map.
2
 
3
   Copyright 2009, 2010 The Go Authors. All rights reserved.
4
   Use of this source code is governed by a BSD-style
5
   license that can be found in the LICENSE file.  */
6
 
7
#include "go-assert.h"
8
#include "map.h"
9
 
10
/* Initialize a range over a map.  */
11
 
12
void
13
__go_mapiterinit (const struct __go_map *h, struct __go_hash_iter *it)
14
{
15
  it->entry = NULL;
16
  if (h != NULL)
17
    {
18
      it->map = h;
19
      it->next_entry = NULL;
20
      it->bucket = 0;
21
      --it->bucket;
22
      __go_mapiternext(it);
23
    }
24
}
25
 
26
/* Move to the next iteration, updating *HITER.  */
27
 
28
void
29
__go_mapiternext (struct __go_hash_iter *it)
30
{
31
  const void *entry;
32
 
33
  entry = it->next_entry;
34
  if (entry == NULL)
35
    {
36
      const struct __go_map *map;
37
      uintptr_t bucket;
38
 
39
      map = it->map;
40
      bucket = it->bucket;
41
      while (1)
42
        {
43
          ++bucket;
44
          if (bucket >= map->__bucket_count)
45
            {
46
              /* Map iteration is complete.  */
47
              it->entry = NULL;
48
              return;
49
            }
50
          entry = map->__buckets[bucket];
51
          if (entry != NULL)
52
            break;
53
        }
54
      it->bucket = bucket;
55
    }
56
  it->entry = entry;
57
  it->next_entry = *(const void * const *) entry;
58
}
59
 
60
/* Get the key of the current iteration.  */
61
 
62
void
63
__go_mapiter1 (struct __go_hash_iter *it, unsigned char *key)
64
{
65
  const struct __go_map *map;
66
  const struct __go_map_descriptor *descriptor;
67
  const struct __go_type_descriptor *key_descriptor;
68
  const char *p;
69
 
70
  map = it->map;
71
  descriptor = map->__descriptor;
72
  key_descriptor = descriptor->__map_descriptor->__key_type;
73
  p = it->entry;
74
  __go_assert (p != NULL);
75
  __builtin_memcpy (key, p + descriptor->__key_offset, key_descriptor->__size);
76
}
77
 
78
/* Get the key and value of the current iteration.  */
79
 
80
void
81
__go_mapiter2 (struct __go_hash_iter *it, unsigned char *key,
82
               unsigned char *val)
83
{
84
  const struct __go_map *map;
85
  const struct __go_map_descriptor *descriptor;
86
  const struct __go_map_type *map_descriptor;
87
  const struct __go_type_descriptor *key_descriptor;
88
  const struct __go_type_descriptor *val_descriptor;
89
  const char *p;
90
 
91
  map = it->map;
92
  descriptor = map->__descriptor;
93
  map_descriptor = descriptor->__map_descriptor;
94
  key_descriptor = map_descriptor->__key_type;
95
  val_descriptor = map_descriptor->__val_type;
96
  p = it->entry;
97
  __go_assert (p != NULL);
98
  __builtin_memcpy (key, p + descriptor->__key_offset,
99
                    key_descriptor->__size);
100
  __builtin_memcpy (val, p + descriptor->__val_offset,
101
                    val_descriptor->__size);
102
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.