
    E#i                     <    S r SSKJr  SSKJrJrJr   " S S5      rg)z-Module with some algorithm utility functions.    )bisect_left)AnyListUnionc                       \ rS rSrSr\S\S\S\4S j5       r	\ SS\
\\4   S\S\4S	 jj5       r\ SS\
\\4   S\S\4S
 jj5       r\S\S\4S j5       rSrg)	AlgoUtils   z0Class container for algorithm utility functions.arrelemreturnc                 R    Sn[        X5      nU[        U 5      :w  a
  X   U:X  a  U$ U$ )z
Binary search algorithm simply implemented by using the bisect library.

Args:
    arr (list): list of elements
    elem (any): element to be searched

Returns:
    int: First index of the element, -1 if not found
)r   len)r
   r   invalid_idxis       f/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/bip/utils/misc/algo.pyBinarySearchAlgoUtils.BinarySearch   s1     "C=SVt^H    dataencodingc                     [        U [        5      (       a  U $ [        U [        5      (       a  U R                  U5      $ [	        S5      e)z
Decode from bytes.

Args:
    data (str or bytes): Data
    encoding (str)     : Encoding type

Returns:
    str: String encoded to bytes

Raises:
    TypeError: If the data is neither string nor bytes
Invalid data type)
isinstancestrbytesdecode	TypeErrorr   r   s     r   DecodeAlgoUtils.Decode5   s>      dC  KdE"";;x((+,,r   c                     [        U [        5      (       a  U R                  U5      $ [        U [        5      (       a  U $ [	        S5      e)z
Encode to bytes.

Args:
    data (str or bytes): Data
    encoding (str)     : Encoding type

Returns:
    bytes: String encoded to bytes

Raises:
    TypeError: If the data is neither string nor bytes
r   )r   r   encoder   r   r   s     r   EncodeAlgoUtils.EncodeK   s>      dC  ;;x((dE""K+,,r   data_strc                 X    [        S U  5       5      =(       a    [        S U  5       5      $ )z
Get if the specified string is in mixed case.

Args:
    data_str (str): string

Returns:
    bool: True if mixed case, false otherwise
c              3   @   #    U  H  oR                  5       v   M     g 7fN)islower.0cs     r   	<genexpr>*AlgoUtils.IsStringMixed.<locals>.<genexpr>l   s     1199;;   c              3   @   #    U  H  oR                  5       v   M     g 7fr)   )isupperr+   s     r   r.   r/   l   s     9Xx!))++xr0   )any)r&   s    r   IsStringMixedAlgoUtils.IsStringMixeda   s%     111Xc9Xx9X6XXr    N)zutf-8)__name__
__module____qualname____firstlineno____doc__staticmethodr   r   intr   r   r   r   r    r$   boolr4   __static_attributes__r6   r   r   r   r      s    :$ #& * &-U5#:& --+.- -* &-U5#:& --+0- -* 
Y 
Y 
Y 
Yr   r   N)r;   bisectr   typingr   r   r   r   r6   r   r   <module>rB      s#   * 4  # #PY PYr   