Opened 6 years ago
Last modified 5 years ago
#622 new enhancement
unused variable in elevator.h
Reported by: | zhaofeng-shu33 | Owned by: | Alpar Juttner |
---|---|---|---|
Priority: | major | Milestone: | LEMON 1.4 release |
Component: | core | Version: | hg main |
Keywords: | Cc: | ||
Revision id: |
Description
There are some unused class private variables in elevator.h. For example, _items[i] for i > 0 (class Elevator); _item_num (class LinkedElevator?).
Change History (4)
comment:1 Changed 6 years ago by
comment:2 Changed 6 years ago by
I check the latest file elevator.h again. _items[0] is used but _items[i] are not used throughout the source code.
Can I make a patch to this file or contribute something equivalent?
comment:3 Changed 6 years ago by
OK, I explain it in more details.
Syntactically, you could indeed replace std::vector<Item> _items
with Item _item
plus every instance of _items[0]
with _item
, and it would compile beautifully. But would crash immediately when trying to use it. Because the whole vector is indeed in heavy use through pointers.
In fact, it is a fundamental part of the data structure. It contains all items ordered by their levels and by there activeness. I.e. it stars with the active items on level 0, then the inactive ones on level 0, then the active ones on level 1, then the inactive ones on level 1 etc.
The vectors _first
and _last_active
indicates the borders of these intervals on each level. In addition, the map _where
gives a cross reference to the elements. The values of these vectors are pointers (Item *
), and the elements of _items
are accessed and manipulated through them.
Right at the beginning, initStart()
puts all items into _item
. Later on, its values are manipulated with the functions copy()
and swap()
.
I hope this helped.
The elements of
_items
are actually used through pointers. I agree it's a bit dirty. As far as I remember is it implemented this way for performance reasons.On the other hand,
_item_num
is indeed unnecessary.