Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Update ArrayMap #50

Merged
merged 5 commits into from
Apr 3, 2024
Merged

Update ArrayMap #50

merged 5 commits into from
Apr 3, 2024

Conversation

hssahota2
Copy link
Collaborator

No description provided.

@hssahota2 hssahota2 marked this pull request as ready for review March 29, 2024 04:38
Copy link
Member

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, but two problems:

  • Comparable doesn't work with Python
  • it's better to centralize all the binarySearch into ListBackedSet, no reason to spread it around

python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
Copy link
Member

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closer!

python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
python/selfie-lib/selfie_lib/ArrayMap.py Show resolved Hide resolved
python/selfie-lib/selfie_lib/ArrayMap.py Outdated Show resolved Hide resolved
@hssahota2 hssahota2 requested a review from nedtwigg April 3, 2024 02:57
Copy link
Member

@nedtwigg nedtwigg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! Much improved, I think this is the last change and ArrayMap will be done!

Comment on lines 10 to 14
class BinarySearchUtil:
@staticmethod
def binary_search(
data, item, compare_func: Optional[Callable[[Any, Any], int]] = None
) -> int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. since we're in Python, this doesn't have to be in a class. It could just be def _binary_search_util(data, item):

  2. This function is only ever called with two parameters -compare_func is always None. The fix is

def _compare_normal(a, b) -> int:
  if a == b:
    return 0
  else if a < b:
    return -1
  else
    return 1

def _compare_string_slash_first(a: str, b : str) -> int:
  return _compare_normal(a.replace("/", "\0"), b.replace("/", "\0"))

def _binary_search(data, item) -> int:
  compare_func = _compare_string_slash_first if item is str else _compare_normal
  low, high = 0, len(data) - 1
  ...
  the rest of the logic, but now you know that compare_func is never None

@hssahota2 hssahota2 requested a review from nedtwigg April 3, 2024 17:25
@nedtwigg nedtwigg merged commit 7f3ce67 into diffplug:main Apr 3, 2024
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants