@@ -1595,228 +1595,4 @@ DAryHeapWithoutReferences.prototype.merge = function ( other ) {
1595
1595
exports . DAryHeapWithoutReferences = DAryHeapWithoutReferences ;
1596
1596
1597
1597
1598
- /* js/src/adt/DoublyLinkedList.js */
1599
- ( function ( ) {
1600
-
1601
- /**
1602
- * Doubly linked list implementation
1603
- * making use of dummy nodes for the
1604
- * sake of simplicity.
1605
- */
1606
-
1607
- var DoublyLinkedList = function ( ) {
1608
- this . front = new Node ( null , null , null ) ;
1609
- this . back = new Node ( this . front , null , null ) ;
1610
- this . front . next = this . back ;
1611
- this . length = 0 ;
1612
- } ;
1613
-
1614
- var Node = function ( prev , next , value ) {
1615
- this . prev = prev ;
1616
- this . next = next ;
1617
- this . value = value ;
1618
- } ;
1619
-
1620
- var Iterator = function ( front , back , current ) {
1621
- this . front = front ;
1622
- this . back = back ;
1623
- this . current = current ;
1624
- } ;
1625
-
1626
- var ReverseIterator = function ( front , back , current ) {
1627
- this . front = front ;
1628
- this . back = back ;
1629
- this . current = current ;
1630
- } ;
1631
-
1632
- DoublyLinkedList . prototype . insertAfter = function ( iterator , value ) {
1633
- var node , prev ;
1634
-
1635
- prev = iterator . current ;
1636
-
1637
- node = new Node ( prev , prev . next , value ) ;
1638
- prev . next . prev = node ;
1639
- prev . next = node ;
1640
-
1641
- ++ this . length ;
1642
- return this . iterator ( node ) ;
1643
- } ;
1644
-
1645
- DoublyLinkedList . prototype . insertBefore = function ( iterator , value ) {
1646
- var node , next ;
1647
-
1648
- next = iterator . current ;
1649
-
1650
- node = new Node ( next . prev , next , value ) ;
1651
- next . prev . next = node ;
1652
- next . prev = node ;
1653
-
1654
- ++ this . length ;
1655
- return this . iterator ( node ) ;
1656
- } ;
1657
-
1658
- DoublyLinkedList . prototype . unshift = function ( value ) {
1659
- return this . insertAfter ( this . begin ( ) , value ) ;
1660
- } ;
1661
-
1662
- DoublyLinkedList . prototype . push = function ( value ) {
1663
- return this . insertBefore ( this . end ( ) , value ) ;
1664
- } ;
1665
-
1666
- DoublyLinkedList . prototype . erase = function ( iterator ) {
1667
- var node = iterator . current ;
1668
-
1669
- node . prev . next = node . next ;
1670
- node . next . prev = node . prev ;
1671
-
1672
- -- this . length ;
1673
- return this . iterator ( node . next ) ;
1674
- } ;
1675
-
1676
- DoublyLinkedList . prototype . rerase = function ( iterator ) {
1677
- var node = iterator . current ;
1678
-
1679
- node . next . prev = node . prev ;
1680
- node . prev . next = node . next ;
1681
-
1682
- -- this . length ;
1683
- return this . iterator ( node . prev ) ;
1684
- } ;
1685
-
1686
- DoublyLinkedList . prototype . eraserange = function ( first , last ) {
1687
- var firstnode , lastnode , it ;
1688
- firstnode = first . current ;
1689
- lastnode = last . current ;
1690
-
1691
- lastnode . prev = firstnode . prev ;
1692
- firstnode . prev . next = lastnode ;
1693
-
1694
- it = first . copy ( ) ;
1695
-
1696
- while ( it . current !== lastnode ) {
1697
- -- this . length ;
1698
- it . next ( ) ;
1699
- }
1700
- return last . copy ( ) ;
1701
- } ;
1702
-
1703
- DoublyLinkedList . prototype . reraserange = function ( first , last ) {
1704
- var firstnode , lastnode , it ;
1705
- firstnode = first . current ;
1706
- lastnode = last . current ;
1707
-
1708
- lastnode . next = firstnode . next ;
1709
- firstnode . next . prev = lastnode ;
1710
-
1711
- it = first . copy ( ) ;
1712
-
1713
- while ( it . current !== lastnode ) {
1714
- -- this . length ;
1715
- it . next ( ) ;
1716
- }
1717
- return last . copy ( ) ;
1718
- } ;
1719
-
1720
- DoublyLinkedList . prototype . shift = function ( ) {
1721
- var it = this . begin ( ) ;
1722
- var e = it . next ( ) ;
1723
-
1724
- if ( e . done ) {
1725
- return null ;
1726
- }
1727
-
1728
- this . rerase ( it ) ;
1729
- return e . value ;
1730
- } ;
1731
-
1732
- DoublyLinkedList . prototype . pop = function ( ) {
1733
- var it = this . rbegin ( ) ;
1734
- var e = it . next ( ) ;
1735
-
1736
- if ( e . done ) {
1737
- return null ;
1738
- }
1739
-
1740
- this . erase ( it ) ;
1741
- return e . value ;
1742
- } ;
1743
-
1744
- DoublyLinkedList . prototype . clear = function ( ) {
1745
- this . front . next = this . back ;
1746
- this . back . prev = this . front ;
1747
- this . length = 0 ;
1748
- return this ;
1749
- } ;
1750
-
1751
- DoublyLinkedList . prototype . iterator = function ( node ) {
1752
- return new Iterator ( this . front , this . back , node ) ;
1753
- } ;
1754
-
1755
- DoublyLinkedList . prototype . riterator = function ( node ) {
1756
- return new ReverseIterator ( this . front , this . back , node ) ;
1757
- } ;
1758
-
1759
- DoublyLinkedList . prototype . begin = function ( ) {
1760
- return this . iterator ( this . front ) ;
1761
- } ;
1762
-
1763
- DoublyLinkedList . prototype . end = function ( ) {
1764
- return this . iterator ( this . back ) ;
1765
- } ;
1766
-
1767
- DoublyLinkedList . prototype . rbegin = function ( ) {
1768
- return this . riterator ( this . back ) ;
1769
- } ;
1770
-
1771
- DoublyLinkedList . prototype . rend = function ( ) {
1772
- return this . riterator ( this . front ) ;
1773
- } ;
1774
-
1775
- Iterator . prototype . copy = function ( ) {
1776
- return new Iterator ( this . front , this . back , this . current ) ;
1777
- } ;
1778
-
1779
- ReverseIterator . prototype . copy = function ( ) {
1780
- return new ReverseIterator ( this . front , this . back , this . current ) ;
1781
- } ;
1782
-
1783
- Iterator . prototype . next =
1784
- ReverseIterator . prototype . prev =
1785
- function ( ) {
1786
- this . current = this . current . next ;
1787
- if ( this . current === this . back ) {
1788
- return { done : true } ;
1789
- }
1790
- else {
1791
- return {
1792
- value : this . current . value ,
1793
- done : false
1794
- } ;
1795
- }
1796
- } ;
1797
-
1798
- Iterator . prototype . prev =
1799
- ReverseIterator . prototype . next =
1800
- function ( ) {
1801
- this . current = this . current . prev ;
1802
- if ( this . current === this . front ) {
1803
- return { done : true } ;
1804
- }
1805
- else {
1806
- return {
1807
- value : this . current . value ,
1808
- done : false
1809
- } ;
1810
- }
1811
- } ;
1812
-
1813
- DoublyLinkedList . Node = Node ;
1814
- DoublyLinkedList . Iterator = Iterator ;
1815
- DoublyLinkedList . ReverseIterator = ReverseIterator ;
1816
-
1817
-
1818
- exports . DoublyLinkedList = DoublyLinkedList ;
1819
-
1820
- } ) ( ) ;
1821
-
1822
1598
} ) ( typeof exports === 'undefined' ? this [ 'datastructures' ] = { } : exports ) ;
0 commit comments