Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

add I example #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

szyrom
Copy link

@szyrom szyrom commented Jul 9, 2020

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.

* Any contribution is more than welcome.
*/
template<typename T>
using matrix_type = typename pmem::obj::vector<persistent_ptr<pmem::obj::vector<T>>>;
Copy link

@igchor igchor Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not vector<vector>?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@szyrom szyrom force-pushed the add_example_I branch 3 times, most recently from 840ba71 to 68db569 Compare July 9, 2020 10:43
@szyrom szyrom force-pushed the add_example_I branch 3 times, most recently from bcdaba8 to 3f704a4 Compare July 9, 2020 13:36
@szyrom szyrom marked this pull request as ready for review July 9, 2020 13:41
@@ -0,0 +1,19 @@
#
# Makefile for finding words examples

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

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:

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,

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 */

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. theoretically
  2. easily

}

/*
* dfs -- deep-frist-search helper function, can be called only from solve()

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

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

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a transaction

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants