Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[project-description] Fix extraction of the ns-3 version.
[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::mc {
20
21 namespace {
22
23 class djb_hash {
24   hash_type state_ = 5381LL;
25
26 public:
27   template<class T>
28   void update(T& x)
29   {
30     state_ = (state_ << 5) + state_ + x;
31   }
32   hash_type value() const { return state_; }
33 };
34
35 }
36
37 hash_type hash(Snapshot const& snapshot)
38 {
39   XBT_DEBUG("START hash %ld", snapshot.num_state_);
40   djb_hash hash;
41   // TODO:
42   // * nb_processes
43   // * heap_bytes_used
44   // * root variables
45   // * basic stack frame information
46   // * stack frame local variables
47   XBT_DEBUG("END hash %ld", snapshot.num_state_);
48   return hash.value();
49 }
50
51 } // namespace simgrid::mc