View Issue Details

IDProjectCategoryView StatusLast Update
0006637JEDI Code LibraryJclQueuespublic2019-09-21 10:46
ReportervirgoparnaAssigned ToAHUser 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0006637: JclQueue classes can have maximum capacity - 1 elements.
DescriptionI noticed, that when I create TJclQueue with capacity 1, then I can't enqueue any objects. And debugging it I discovered, that actual problem is in all queue classes and is, that if queue size equal to capacity - 1, then it can't add any more elements because it fails to grow.
Additional InformationFollowing sample program demonstrates the problem (program output will be:
Enqueueing HELLO failed
Enqueueing WORLD failed
).

(********************************************)
program queue;
{$APPTYPE CONSOLE}
uses
  JclContainerIntf, JclQueues;
var
  SQ: IJclStrQueue;
begin
  SQ := TJclStrQueue.Create(1);
  if not SQ.Enqueue('HELLO') then
    writeln('Enqueueing HELLO failed')
  else
    writeln('Enqueueing HELLO succeeded');
  if not SQ.Enqueue('WORLD') then
    writeln('Enqueueing WORLD failed')
  else
    writeln('Enqueueing WORLD succeeded');
end.
(********************************************)

Simplest solution would be to override AutoGrow for all Queue classes as:
  //+ 1 is needed, because queue must be 1 larger
  if FHead > FTail then
    SetCapacity(CalcGrowCapacity(FCapacity, FCapacity - FHead + FTail +
1)) // looped
  else
    SetCapacity(CalcGrowCapacity(FCapacity, FTail - FHead + 1));

Actually, all AbstractContainer methods using FSize will need overriding
because Queue classes do not use FSize and it is always 0. That is
separate issue.
TagsNo tags attached.
Fixed in revision
IDE versionAll

Activities

AHUser

2019-09-21 10:46

developer   ~0021893

Merge pull request that fixes the issue

Issue History

Date Modified Username Field Change
2018-06-05 09:57 virgoparna New Issue
2018-06-05 09:57 virgoparna IDE version => All
2019-09-21 10:46 AHUser Assigned To => AHUser
2019-09-21 10:46 AHUser Status new => resolved
2019-09-21 10:46 AHUser Resolution open => fixed
2019-09-21 10:46 AHUser Note Added: 0021893