





'''simple docstring'''



from __future__ import annotations

from collections import deque






class 							__lowercase       :







	'''simple docstring'''

	def __init__(self     ,_lowerCamelCase )							->							int:







				'''simple docstring'''





				__lowercase										=							[]
				self.adlist.append(
				    {'''value''': '''''', '''next_states''': [], '''fail_state''': 0, '''output''': []} )

				for keyword in keywords:
							self.add_keyword(_lowerCamelCase )
				self.set_fail_transitions()


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase )							->							int | None:







				'''simple docstring'''





				for state in self.adlist[current_state]["next_states"]:
							if char == self.adlist[state]["value"]:
										return state
				return None


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase )							->							None:







				'''simple docstring'''





				__lowercase										=							0
				for character in keyword:
							__lowercase										=							self.find_next_state(_lowerCamelCase     ,_lowerCamelCase )
							if next_state is None:
										self.adlist.append(
										    {
										        '''value''': character,
										        '''next_states''': [],
										        '''fail_state''': 0,
										        '''output''': [],
										    } )
										self.adlist[current_state]["next_states"].append(len(self.adlist ) - 1 )
										__lowercase										=							len(self.adlist ) - 1
							else:
										__lowercase										=							next_state
				self.adlist[current_state]["output"].append(_lowerCamelCase )


	def 						_UpperCAmelCase     (self )							->							None:







				'''simple docstring'''





				__lowercase										=							deque()
				for node in self.adlist[0]["next_states"]:
							q.append(_lowerCamelCase )
							__lowercase										=							0
				while q:
							__lowercase										=							q.popleft()
							for child in self.adlist[r]["next_states"]:
										q.append(_lowerCamelCase )
										__lowercase										=							self.adlist[r]['''fail_state''']
										while (
										    self.find_next_state(_lowerCamelCase     ,self.adlist[child]['''value'''] ) is None
										    and state != 0
										):
													__lowercase										=							self.adlist[state]['''fail_state''']
										__lowercase										=							self.find_next_state(
										    _lowerCamelCase     ,self.adlist[child]['''value'''] )
										if self.adlist[child]["fail_state"] is None:
													__lowercase										=							0
										__lowercase										=							(
										    self.adlist[child]['''output''']
										    + self.adlist[self.adlist[child]['''fail_state''']]['''output''']
										)


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase )							->							dict[str, list[int]]:







				'''simple docstring'''





				__lowercase										=							{}  # returns a dict with keywords and list of its occurrences
				__lowercase										=							0
				for i in range(len(_lowerCamelCase ) ):
							while (
							    self.find_next_state(_lowerCamelCase     ,string[i] ) is None
							    and current_state != 0
							):
										__lowercase										=							self.adlist[current_state]['''fail_state''']
							__lowercase										=							self.find_next_state(_lowerCamelCase     ,string[i] )
							if next_state is None:
										__lowercase										=							0
							else:
										__lowercase										=							next_state
										for key in self.adlist[current_state]["output"]:
													if key not in result:
																__lowercase										=							[]
													result[key].append(i - len(_lowerCamelCase ) + 1 )
				return result


if __name__ == "__main__":
	import doctest

	doctest.testmod()












'''simple docstring'''



from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


_SCREAMING_SNAKE_CASE					=    {'''configuration_van''': ['''VAN_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''VanConfig''']}


try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_SCREAMING_SNAKE_CASE					=    [
	    '''VAN_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''VanForImageClassification''',
	    '''VanModel''',
	    '''VanPreTrainedModel''',
	]

if TYPE_CHECKING:
	from .configuration_van import VAN_PRETRAINED_CONFIG_ARCHIVE_MAP, VanConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_van import (
		    VAN_PRETRAINED_MODEL_ARCHIVE_LIST,
		    VanForImageClassification,
		    VanModel,
		    VanPreTrainedModel,
		)

else:
	import sys

	_SCREAMING_SNAKE_CASE					=    _LazyModule(__name__, globals()['''__file__'''], _import_structure)





