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

Commit

Permalink
add I example
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Romik committed Jul 9, 2020
1 parent bb6326e commit bcdaba8
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/I/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_words
19 changes: 19 additions & 0 deletions examples/I/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Makefile for finding words examples
#
OBJS = find_words.o
LIBS = -lpmemobj -lpmem

all: find_words

find_words: $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS)

clean:
$(RM) *.o core a.out

clobber: clean
$(RM) find_words

.PHONY: all clean clobber

32 changes: 32 additions & 0 deletions examples/I/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
C++ data structures in persistent memory

In this example, we will solve a simple algorithmic problem using data
structures which resides in persistent memory. We will use persistent containers
from libpmemobj-cpp library.

C++ programmers will get the most out of this example.

This is example consists of these files:

dictionary.txt -- a file with some words which represents a dictionary
board.txt -- a file with characters in a form of 2D matrix
Makefile -- rules for building all the programs in this example
trie.hpp -- a simple trie structure implementation for persistent
memory
find_words.cpp -- C++ program for finding words, program can continue
search process after the crash happen
run.sh -- run the find_words example

To build the program in this example run: make
To run it, use the run.sh script.

Modifying the code and run steps is a great way to learn from this example.

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,
right, top, bottom), each cell can be used only once when creating a single
word.

We will solve this problem, creating trie and performing DFS from every board
cell, saving current results in on a persistent memory.
4 changes: 4 additions & 0 deletions examples/I/board.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
metep
ensrx
mtisx
oryxx
1 change: 1 addition & 0 deletions examples/I/dictionary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
persistent memory and nothing else
Loading

0 comments on commit bcdaba8

Please sign in to comment.