FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
vertex_pointer.h
1 #ifndef __VERTEX_POINTER_H__
2 #define __VERTEX_POINTER_H__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of FlashGraph.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 #include <stdlib.h>
23 
24 namespace fg
25 {
26 
27 class compute_vertex;
28 
29 class compute_vertex_pointer
30 {
31  static const int PART_BIT_LOC = 48;
32  // TODO This is Linux specific.
33  static const uint64_t PART_MASK = 0xFFFF000000000000UL;
34  static const uint64_t ADDR_MASK = 0x0000FFFFFFFFFFFFUL;
35  uint64_t addr;
36 public:
37  static compute_vertex **conv(compute_vertex_pointer *arr) {
38  assert(sizeof(compute_vertex_pointer) == sizeof(arr[0]));
39  return (compute_vertex **) arr;
40  }
41 
42  compute_vertex_pointer() {
43  addr = 0;
44  }
45 
46  explicit compute_vertex_pointer(compute_vertex *v) {
47  assert(v);
48  addr = (uint64_t) v;
49  assert(addr > 100000);
50  }
51 
52  compute_vertex_pointer(compute_vertex *v, bool part) {
53  assert(v);
54  assert(((uint64_t) v) > 100000);
55  addr = ((uint64_t) v) + (((uint64_t) part) << PART_BIT_LOC);
56  }
57 
58  bool is_part() const {
59  return addr & PART_MASK;
60  }
61 
62  bool is_valid() const {
63  return (addr & ADDR_MASK) != 0;
64  }
65 
66  compute_vertex *get() const {
67  assert((addr & ADDR_MASK) != 0);
68  return (compute_vertex *) (uintptr_t) (addr & ADDR_MASK);
69  }
70 
71  compute_vertex *operator->() const {
72  return get();
73  }
74 
75  compute_vertex &operator*() const {
76  return *get();
77  }
78 };
79 
80 }
81 
82 #endif