Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2008
peterlspot peterlspot is offline
Registered User
 
Name: Peter Lau
Organization: Self
Project: Study
 
Join Date: Nov 2007
Posts: 13
ways to get the max&min value of a Freeze map index?

Dear pals,

Just wonder if there r any C++ API to retrieve the current maximum and minimum values of a particular index field in a freeze map?

Suppose there is students map based on the following SLICE:

Quote:
class Student
{
int id;
string name;
}
and the corresponding freeze map is indexed on the field "id".

Is there any ways to find out the current min & max values of the "id" field stored in the student map.

Thanks
__________________
Peter Lau
No pains, no gains.
Lifelong programming ...
Reply With Quote
  #2 (permalink)  
Old 01-08-2008
matthew's Avatar
matthew matthew is online now
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,061
Indexed fields will generate additional methods. From the Ice manual:

Code:
iterator findByMEMBER(MEMBER_TYPE, bool = true); 
const_iterator findByMEMBER(MEMBER_TYPE, bool = true) const; 
iterator lowerBoundForMEMBER(MEMBER_TYPE); 
const_iterator lowerBoundForMEMBER(MEMBER_TYPE) const; 
iterator upperBoundForMEMBER(MEMBER_TYPE); 
const_iterator upperBoundForMEMBER(MEMBER_TYPE) const; 
std::pair<iterator, iterator> 
equalRangeForMEMBER(MEMBER_TYPE); 
std::pair<const_iterator, const_iterator> 
equalRangeForMEMBER(MEMBER_TYPE) const; 
int MEMBERCount(MEMBER_TYPE) const;
You should also check issue 11 of our newsletter connections which has an article on these methods.

Following, assuming that you also set the sort function to less<int> then to find the lowest id you could do:

m.lowerBoundForId(0);

which will return an iterator to either the record with id 0, or the first record after this. In either case, assuming you never store records with an id < 0 then you are all set

Unfortunately, computing the biggest id is more difficult. You might think you could use upperBoundForId:

m.upperBoundForId(MAX_INT);

However, since you cannot iterate backwards with a freeze map iterator (they are not bidirectional iterators) then this return value does you no good.

Some alternate solutions to help:
- You could create another id field id2 that contains an identical id, index upon that and sort in the opposite direction (greater<int>). Then lowerBoundForId2(MAX_INT) would find the biggest id.
- You could create a dummy record and sort the biggest id in that field and use lowerBoundForId to find the lowest.
- You could compute the biggest and smallest on startup and cache them during the application run.

All things being equal likely the last is the simplest solution.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Freeze::ConnectionPtr from Freeze::Map Obj paolo Comments 1 01-05-2008 06:02 PM
getting normal map from freeze map ctennis Help Center 2 03-09-2007 08:48 AM
slice2cpp -U to undef min and max macros StuartA Help Center 2 05-08-2006 03:24 AM
Freeze map ordering dwk Help Center 1 04-26-2004 08:44 PM
Freeze::map.lower_bound sylvain Comments 3 07-20-2003 02:12 PM


All times are GMT -4. The time now is 12:40 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.