Inverted index: Difference between revisions

Content added Content deleted
(→‎{{header|D}}: added D)
(→‎{{header|D}}: regex splitter)
Line 966: Line 966:


=={{header|D}}==
=={{header|D}}==
<lang d>import std.stdio, std.algorithm, std.file, std.string;
<lang d>import std.stdio, std.algorithm, std.file, std.string, std.regex;


void parseFile(in string fn, ref string[][string] idx) {
void parseFile(in string fn, ref string[][string] idx) {
Line 972: Line 972:
throw new Exception("File not found");
throw new Exception("File not found");


foreach (word; readText(fn).splitter()) {
foreach (word; readText(fn).splitter(regex(r"\W"))) {
if (word in idx) {
if (word in idx) {
if (canFind(idx[word], fn))
if (canFind(idx[word], fn))