Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / mc / mc_hash.cpp
1 /* Copyright (c) 2014-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <cinttypes>
7 #include <cstdint>
8
9 #include "xbt/log.h"
10
11 #include "mc/datatypes.h"
12 #include "src/mc/mc_hash.hpp"
13 #include "src/mc/mc_private.hpp"
14 #include "src/mc/sosp/Snapshot.hpp"
15 #include <mc/mc.h>
16
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_hash, mc, "Logging specific to mc_hash");
18
19 namespace simgrid {
20 namespace mc {
21
22 namespace {
23
24 class djb_hash {
25   hash_type state_ = 5381LL;
26
27 public:
28   template<class T>
29   void update(T& x)
30   {
31     state_ = (state_ << 5) + state_ + x;
32   }
33   hash_type value() const { return state_; }
34 };
35
36 }
37
38 hash_type hash(Snapshot const& snapshot)
39 {
40   XBT_DEBUG("START hash %i", snapshot.num_state_);
41   djb_hash hash;
42   // TODO:
43   // * nb_processes
44   // * heap_bytes_used
45   // * root variables
46   // * basic stack frame information
47   // * stack frame local variables
48   XBT_DEBUG("END hash %i", snapshot.num_state_);
49   return hash.value();
50 }
51
52 }
53 }