Skip to content

Commit

Permalink
Make Symbol and File type hashables
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Aug 6, 2023
1 parent 9ad03c2 commit 5b60ad8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[project]
name = "mapfile_parser"
version = "1.3.0"
version = "1.3.1.dev0"
description = "Map file parser library focusing decompilation projects"
readme = "README.md"
requires-python = ">=3.7"
Expand Down
4 changes: 2 additions & 2 deletions src/mapfile_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from __future__ import annotations

__version_info__ = (1, 3, 0)
__version__ = ".".join(map(str, __version_info__))
__version_info__ = (1, 3, 1)
__version__ = ".".join(map(str, __version_info__)) + ".dev0"
__author__ = "Decompollaborate"

from . import utils as utils
Expand Down
20 changes: 20 additions & 0 deletions src/mapfile_parser/mapfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def toJson(self) -> dict:
return result


def __eq__(self, other: object) -> bool:
if not isinstance(other, Symbol):
return False
return self.name == other.name and self.vram == other.vram

# https://stackoverflow.com/a/56915493/6292472
def __hash__(self):
return hash((self.name, self.vram))


@dataclasses.dataclass
class File:
filepath: Path
Expand Down Expand Up @@ -192,6 +202,16 @@ def __iter__(self) -> Generator[Symbol, None, None]:
def __getitem__(self, index) -> Symbol:
return self.symbols[index]

def __eq__(self, other: object) -> bool:
if not isinstance(other, File):
return False
return self.filepath == other.filepath

# https://stackoverflow.com/a/56915493/6292472
def __hash__(self):
return hash((self.filepath,))


@dataclasses.dataclass
class FoundSymbolInfo:
file: File
Expand Down

0 comments on commit 5b60ad8

Please sign in to comment.