Skip to content

Conversation

@Sreevarsh-Mahesh
Copy link

References to other Issues or PRs or Relevant literature

Fixes #692

Brief description of what is fixed or changed

This PR implements a memory-efficient XOR-based doubly linked list mode for DoublyLinkedList.

What is XOR Linked List?
An XOR linked list stores a single pointer containing the XOR of adjacent node addresses instead of two separate pointers, reducing memory usage while maintaining bidirectional traversal capability.

Implementation:

  • Added mode parameter to DoublyLinkedList.__new__() with options: 'standard' (default) or 'xor'
  • Implemented XOR node structure using links=['both'] to store XOR of adjacent node IDs
  • Added _id_to_node dictionary for node reference tracking (simulates pointer dereferencing in Python)
  • Refactored all insert/extract methods to support both modes: insert_after(), insert_before(), insert_at(), extract()
  • Overrode __getitem__(), __str__(), and search() for XOR traversal support
  • Maintained full backward compatibility with standard mode

Testing:

  • Added 4 comprehensive test functions for XOR mode
  • test_DoublyLinkedList_XOR() - Full feature test matching standard mode behavior
  • test_DoublyLinkedList_XOR_vs_Standard() - Parity test between modes
  • test_DoublyLinkedList_XOR_EdgeCases() - Edge cases (empty, single, large lists)
  • test_DoublyLinkedList_InvalidMode() - Error handling
  • All 114 existing tests still pass (100% backward compatible)

Usage Example:

from pydatastructs import DoublyLinkedList

# XOR mode for memory efficiency
dll_xor = DoublyLinkedList(mode='xor')
dll_xor.append(1)
dll_xor.append(2)
dll_xor.append(3)
# Produces identical results to standard mode!

Implements issue codezonediitj#692 by adding an optional 'xor' mode to DoublyLinkedList
that uses XOR of adjacent node addresses to reduce memory usage from 2
pointers to 1 pointer per node.

Features:
- Add mode parameter ('standard' or 'xor') to DoublyLinkedList.__new__
- Implement XOR node structure with links=['both']
- Maintain id_to_node dictionary for pointer dereferencing
- Refactor all insert/extract methods for XOR mode support
- Override __getitem__, __str__, and search for XOR traversal
- Maintain full backward compatibility with standard mode

Testing:
- Add comprehensive test suite for XOR mode
- Test parity between standard and XOR modes
- Test edge cases (empty, single, large lists)
- All 114 existing tests still pass

Fixes codezonediitj#692
Copilot AI review requested due to automatic review settings December 8, 2025 08:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Memory Efficient Doubly Linked List

1 participant