Skip to content

Commit

Permalink
Merge pull request #288 from cavokz/speed-up-high-cardinality-generation
Browse files Browse the repository at this point in the history
Speed up generation of (some) high cardinality data
  • Loading branch information
cavokz committed May 7, 2024
2 parents 072d4eb + 2cfcdfa commit d0ad493
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 4 additions & 3 deletions geneve/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import functools
import json
import re
import shutil
import sys
from contextlib import contextmanager
Expand All @@ -32,12 +33,12 @@
from . import dirs, epr

random = Random()
wc_re = re.compile(r"\*|\?")


def has_wildcards(s):
if not isinstance(s, str):
return False
return s.find("?") + s.find("*") > -2
if isinstance(s, str):
return bool(wc_re.search(s))


def expand_wildcards(s, alphabet, min_star_len, max_star_len):
Expand Down
15 changes: 10 additions & 5 deletions geneve/utils/solution_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ def __bool__(self):
def __contains__(self, item):
if self.__exclude and item in self.__exclude:
return False
return (
self.__set == everything()
or any(item == value for value, _ in self.__set)
or any(fnmatchcase(str(item).lower(), str(value).lower()) for value, _ in self.__set)
)
if self.__set == everything():
return True
item = str(item).lower()
for value, wc in self.__set:
value = str(value).lower()
if item == value:
return True
if wc and fnmatchcase(item, value):
return True
return False

def __and__(self, other):
ss = self.__copy__()
Expand Down
1 change: 1 addition & 0 deletions tests/test_solution_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TestStrings(tu.SeededTestCase, unittest.TestCase):
def test_contains(self):
testcases = [
("a", "a", True),
("a", "A", True),
("aa", "a", False),
("a", "aa", False),
("a?", "a?", True),
Expand Down

0 comments on commit d0ad493

Please sign in to comment.