


"""simple docstring"""


from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

A  :     Any    					=    TypeVar("T")
A  :     Optional[int]    					=    TypeVar("U")



class 						_UpperCamelCase						(     Generic[T, U]	):
							'''simple docstring'''







							def __init__(  self					,     __a					,     __a			):
										__lowerCAmelCase       					=    key
										__lowerCAmelCase       					=    val
										__lowerCAmelCase       					=    None
										__lowerCAmelCase       					=    None



							def __repr__(  self			):
										return (
										    f"Node: key: {self.key}, val: {self.val}, "
										    f"has next: {bool(self.next			)}, has prev: {bool(self.prev			)}"
										)



class 						_UpperCamelCase						(     Generic[T, U]	):
							'''simple docstring'''







							def __init__(  self			):
										__lowerCAmelCase       					=    DoubleLinkedListNode(A__					,     A__			)
										__lowerCAmelCase       					=    DoubleLinkedListNode(A__					,     A__			)
										__lowerCAmelCase					,			__lowerCAmelCase       					=    self.rear, self.head

							def __repr__(  self			):
										__lowerCAmelCase       					=    ["DoubleLinkedList"]
										__lowerCAmelCase       					=    self.head
										while node.next is not None:
													rep.append(str(A__			)			)
													__lowerCAmelCase       					=    node.next
										rep.append(str(self.rear			)			)
										return ",\n    ".join(A__			)

							def     snake_case       (  self					,     __a			):
										__lowerCAmelCase       					=    self.rear.prev

										# All nodes other than self.head are guaranteed to have non-None previous
										assert previous is not None

										__lowerCAmelCase       					=    node
										__lowerCAmelCase       					=    previous
										__lowerCAmelCase       					=    node
										__lowerCAmelCase       					=    self.rear



							def     snake_case       (  self					,     __a			):

										if node.prev is None or node.next is None:
													return None

										__lowerCAmelCase       					=    node.next
										__lowerCAmelCase       					=    node.prev
										__lowerCAmelCase       					=    None
										__lowerCAmelCase       					=    None
										return node



class 						_UpperCamelCase						(     Generic[T, U]	):
							'''simple docstring'''







							__UpperCAmelCase		:					str          ={}

							def __init__(  self					,     __a			):
										__lowerCAmelCase       					=    DoubleLinkedList()
										__lowerCAmelCase       					=    capacity
										__lowerCAmelCase       					=    0
										__lowerCAmelCase       					=    0
										__lowerCAmelCase       					=    0
										__lowerCAmelCase       					=    {}

							def __repr__(  self			):
										return (
										    f"CacheInfo(hits={self.hits}, misses={self.miss}, "
										    f"capacity={self.capacity}, current size={self.num_keys})"
										)

							def __contains__(  self					,     __a			):
										return key in self.cache

							def     snake_case       (  self					,     __a			):
										# Note: pythonic interface would throw KeyError rather than return None

										if key in self.cache:
													self.hits += 1
													__lowerCAmelCase       					=    self.cache[key]
													__lowerCAmelCase       					=    self.list.remove(self.cache[key]			)
													assert node == value_node

													# node is guaranteed not None because it is in self.cache
													assert node is not None
													self.list.add(A__			)
													return node.val
										self.miss += 1
										return None

							def     snake_case       (  self					,     __a					,     __a			):

										if key not in self.cache:
													if self.num_keys >= self.capacity:
																# delete first node (oldest) when over capacity
																__lowerCAmelCase       					=    self.list.head.next

																# guaranteed to have a non-None first node when num_keys > 0
																# explain to type checker via assertions
																assert first_node is not None
																assert first_node.key is not None
																assert (
																    self.list.remove(A__			) is not None
																)  # node guaranteed to be in list assert node.key is not None

																del self.cache[first_node.key]
																self.num_keys -= 1
													__lowerCAmelCase       					=    DoubleLinkedListNode(A__					,     A__			)
													self.list.add(self.cache[key]			)
													self.num_keys += 1

										else:
													# bump node to the end of the list, update value
													__lowerCAmelCase       					=    self.list.remove(self.cache[key]			)
													assert node is not None  # node guaranteed to be in list
													__lowerCAmelCase       					=    value
													self.list.add(A__			)



							@classmethod
							def     snake_case       (  cls					,     __a = 1_28			):

										def cache_decorator_inner(__a			) -> Callable[..., U]:
													def cache_decorator_wrapper(*__a			) -> U:
																if func not in cls.decorator_function_to_instance_map:
																			__lowerCAmelCase       					=    LRUCache(A__			)

																__lowerCAmelCase       					=    cls.decorator_function_to_instance_map[func].get(args[0]			)
																if result is None:
																			__lowerCAmelCase       					=    func(*A__			)
																			cls.decorator_function_to_instance_map[func].put(args[0]					,     A__			)
																return result

													def cache_info() -> LRUCache[T, U]:
																return cls.decorator_function_to_instance_map[func]

													setattr(A__					,     "cache_info"					,     A__			)  # noqa: B010

													return cache_decorator_wrapper

										return cache_decorator_inner


if __name__ == "__main__":
	import doctest

	doctest.testmod()








"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A  :     Union[str, Any]    					=    {
    "configuration_x_clip": [
        "XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "XCLIPConfig",
        "XCLIPTextConfig",
        "XCLIPVisionConfig",
    ],
    "processing_x_clip": ["XCLIPProcessor"],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A  :     Optional[int]    					=    [
	    "XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
	    "XCLIPModel",
	    "XCLIPPreTrainedModel",
	    "XCLIPTextModel",
	    "XCLIPVisionModel",
	]

if TYPE_CHECKING:
	from .configuration_x_clip import (
	    XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    XCLIPConfig,
	    XCLIPTextConfig,
	    XCLIPVisionConfig,
	)
	from .processing_x_clip import XCLIPProcessor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_x_clip import (
		    XCLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
		    XCLIPModel,
		    XCLIPPreTrainedModel,
		    XCLIPTextModel,
		    XCLIPVisionModel,
		)

else:
	import sys

	A  :     Union[str, Any]    					=    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




