Git Product home page Git Product logo

Comments (12)

joachimschmidt557 avatar joachimschmidt557 commented on June 29, 2024 1

Yup, I'll make another issue for adding more algorithms.

from string-searching.

joachimschmidt557 avatar joachimschmidt557 commented on June 29, 2024 1

Hmm okay, support for types that follow 2 rules can be added:

  • indexable
  • length can be queried

That would include slices as well as vectors, I suppose.

from string-searching.

joachimschmidt557 avatar joachimschmidt557 commented on June 29, 2024 1

Implemented in 15a7ec2

from string-searching.

joachimschmidt557 avatar joachimschmidt557 commented on June 29, 2024

Yup, this is definitely a feature worth having. However, arbitrary types can't be supported as all possible elements of the type (in the case of u8 there are 256 possible elements) need to be known in order to add them to the bad character table.

from string-searching.

joachimschmidt557 avatar joachimschmidt557 commented on June 29, 2024

I'd suggest supporting all integer (signed and unsigned, or maybe just unsigned?) types.

from string-searching.

data-man avatar data-man commented on June 29, 2024

Oh, sorry! I forgot about the limitations of the algorithm. :(
Knuth–Morris–Pratt algorithm is more suitable for any type.

Just an idea: rename this repository to zig-search-algorithms or something like this.
And add other popular algorithms.

from string-searching.

data-man avatar data-man commented on June 29, 2024

There is awesome String Matching Algorithms Research Tool but it is GPL-licensed.

from string-searching.

data-man avatar data-man commented on June 29, 2024

I think new name zig-string-searching is slightly incorrect now. :)
I suggest use zig-pattern-searching.

from string-searching.

joachimschmidt557 avatar joachimschmidt557 commented on June 29, 2024

Hmm, pattern kind of implies some regex-ish matching. According to Wikipedia, "string-searching algorithm" is the term for this family of algorithms.

from string-searching.

data-man avatar data-man commented on June 29, 2024

Sure, but structs are't strings (if new algorithms are added).

from string-searching.

joachimschmidt557 avatar joachimschmidt557 commented on June 29, 2024

I think that we want to limit the scope of this repository to slices of some type T, i.e. searching for a []const T in another []const T. This is basically equivalent to the mathematical definition of strings, which are finite sequences of symbols from an alphabet. The alphabet would be T in this case.

This does not prevent us from choosing some struct for T. We would have to include some equality function in that case because structs cannot be compared with the == operator anymore.

For example:

const Abc = struct {
    id: usize,
    some_data: []const u8,

    pub fn equals(self: Abc, other: Abc) bool {
        return self.id == other.id;
    }
};

We can then search for a []const Abc in a []const Abc if we want to.

from string-searching.

data-man avatar data-man commented on June 29, 2024

std.meta.trait.isIndexable now supports vectors.
So potentially, some algorithms could use this trait.
But I'm waiting when ziglang/zig#5443 will be merged.

from string-searching.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.