Skip to content

Commit 6c15803

Browse files
committed
debug_ docs
1 parent ceb2544 commit 6c15803

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

lib/dmp/debug_utils.ex

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ defmodule Dmp.DebugUtils do
55

66
use Bitwise, only_operators: true
77

8-
@smallint_len 14
9-
108
@doc """
11-
Formats the `alphabet` bitarray into a list of lines, showing binary values.
9+
Formats an alphabet bitarray into a list of lines, showing binary values.
10+
11+
* `s` - The alphabet as returned by `Dmp.Match.alphabet/1`.
12+
* `pattern` - The pattern that is associated with the alphabet.
1213
1314
## Examples
1415
15-
iex> DebugUtils.debug_alphabet("aba", %{?a => 5, ?b => 2})
16+
iex> DebugUtils.debug_alphabet(%{?a => 5, ?b => 2}, "aba")
1617
[
1718
"alphabet: a b a",
1819
" a 5: 1 0 1",
1920
" b 2: 0 1 0"
2021
]
2122
2223
"""
23-
@spec debug_alphabet(String.t(), Dmp.Match.alpha()) :: [String.t()]
24-
def debug_alphabet(pattern, s) do
24+
@spec debug_alphabet(Dmp.Match.alpha(), String.t()) :: [String.t()]
25+
def debug_alphabet(s, pattern) do
2526
pattern_length = String.length(pattern)
2627
int_len = value_size(pattern_length)
2728

@@ -52,13 +53,18 @@ defmodule Dmp.DebugUtils do
5253
@doc """
5354
Formats the `rd` bitarray into a list of lines, showing binary values.
5455
55-
* `d` - Error level for the bitarray.
56-
* `start` - Lowest index that has been calculated.
57-
* `best_loc` - Index in the text where the best match has been found.
56+
* `rd` - The bitarrary.
57+
* `text` - The text associated with `rd`.
58+
* `pattern` - The pattern associated with `rd`.
59+
* `d` - The error level.
60+
* `start` - The lowest index that has been calculated. Lines below this
61+
index will be marked with an asterisk.
62+
* `best_loc` - The index in the text where the best match has been found.
63+
The line at this index will be marked with an "@"-sign.
5864
5965
## Examples
6066
61-
iex> DebugUtils.debug_rd("abc", "add", 0, %{1 => 5, 2 => 7, -1 => 3}, 1, 2)
67+
iex> DebugUtils.debug_rd(%{1 => 5, 2 => 7, -1 => 3}, "abc", "add", 0, 1, 2)
6268
[
6369
" rd_j^0: a d d",
6470
" 0* _ 0: 0 0 0",
@@ -70,14 +76,14 @@ defmodule Dmp.DebugUtils do
7076
7177
"""
7278
@spec debug_rd(
79+
Dmp.Match.bitap_array(),
7380
String.t(),
7481
String.t(),
7582
non_neg_integer(),
76-
Dmp.Match.bitap_array(),
7783
non_neg_integer(),
7884
integer()
7985
) :: [String.t()]
80-
def debug_rd(text, pattern, d, rd, start \\ 0, best_loc \\ -1) do
86+
def debug_rd(rd, text, pattern, d, start \\ 0, best_loc \\ -1) do
8187
pattern_length = String.length(pattern)
8288
int_len = value_size(pattern_length)
8389
rd_size = max(String.length(text) + 2, Map.fetch!(rd, -1))

lib/dmp/match.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ defmodule Dmp.Match do
129129
match_distance}
130130

131131
# Uncomment to see the bitarray
132-
# debug_alphabet(pattern, s) |> Enum.join("\n") |> IO.puts
132+
# debug_alphabet(s, pattern) |> Enum.join("\n") |> IO.puts
133133

134134
# Start with `max_distance = text_length + pattern_length`
135135
# and the $$R_{j}^0$$ array all zero (empty map).
@@ -246,13 +246,13 @@ defmodule Dmp.Match do
246246
bitap_update(j, acc, constants2)
247247
end)
248248

249-
# See if the threshold for match at level `d + 1` is lower than the best
250-
# score we found at this level, in which case we have to continue to
251-
# that level.
249+
# See if the best threshold for a match at location `loc` and
250+
# at error level `d + 1` is lower than the best score we found at
251+
# this level, in which case we have to continue to level `d + 2.
252252
d1_score = bitap_score(d + 1, loc, loc, pattern_length, match_distance)
253253

254254
# Uncomment to see the bitarray
255-
# debug_rd(text, pattern, d, rd, j, best_loc) |> Enum.join("\n") |> IO.puts
255+
# debug_rd(rd, text, pattern, d, j, best_loc) |> Enum.join("\n") |> IO.puts
256256

257257
if d1_score > score_threshold do
258258
# No hope for a (better) match at greater error levels.

0 commit comments

Comments
 (0)