-
Notifications
You must be signed in to change notification settings - Fork 6
add I example #1
base: master
Are you sure you want to change the base?
Conversation
examples/I/find_words.cpp
Outdated
* Any contribution is more than welcome. | ||
*/ | ||
template<typename T> | ||
using matrix_type = typename pmem::obj::vector<persistent_ptr<pmem::obj::vector<T>>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not vector<vector>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
840ba71
to
68db569
Compare
bcdaba8
to
3f704a4
Compare
@@ -0,0 +1,19 @@ | |||
# | |||
# Makefile for finding words examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples -> example
// Insert a new value in transaction in order to guarantee | ||
// data consistency and atomicty. If we want to perform | ||
// transaction in a specyfic persistent memory pool, we need a | ||
// pool handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add "." at the end
|
||
C++ programmers will get the most out of this example. | ||
|
||
This is example consists of these files: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop "is"
|
||
In this example we are given a problem to solve: | ||
In a 2-D matrix of characters (board.txt) we must find all the words from a | ||
dictionary (dictionary.txt). Words can be formed from the adjecent cells (left, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjacent
#include "trie.hpp" | ||
#include "hashset.hpp" | ||
|
||
/* A unique layoout of the peristent memory pool that we are going to use */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layout
* std::pair for trivial types is implemented in all the C++ standard libraries | ||
* in the same way and most of the well know compilers define this structure | ||
* layout exactly the same. | ||
* Using std::pair is theoreatically undefined behaviour, we could easly use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- theoretically
- easily
} | ||
|
||
/* | ||
* dfs -- deep-frist-search helper function, can be called only from solve() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deep? not depth?
curr_word += board[i][j]; | ||
board[i][j] += 26; // mark as checked | ||
|
||
if (trie_root.find_prefix(curr_word)) { // it is existing prefix, continue dfs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an existing
# shell commands to run find_words example | ||
# | ||
|
||
# show the contents of the imput data set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input ;)
class trie { | ||
|
||
struct trieNode { | ||
// Note that we are declareing pmem::obj::array of children |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declaring
* Insert a word to the trie. | ||
*/ | ||
void insert(const std::string &word) { | ||
// Insert a new value in transaction in order to guarantee |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a transaction
The main intention in this example is to show how to use persistent memory containers from libpmemobj-cpp library.
The example also highlights structures/classes layout issues on persistent memory, describes peristent_ptr dereference overhead, and shows good practices when designing structures for persistent memory with data-oriented design in mind.