Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Last X elements request

Posted on 2012-08-30
Medium Priority
394 Views
Hi,

I have to connect to a server with basic function. One function give me the number of elements and one function give me the elements after I provide the page which I want and the size of the page which can be biiger that 100

What I want is to get last X elements from the list with one call.

Example: I have 230 elements from one request to get last 29 elements. One first look solution is page 5 with 50 elements on the page and remove the top until remain 29 elements

My question is: How can calculate in the proper way wich is the last page and size of the page that give to me my elements?
0
Question by:Syberye
• 4
• 4
• 2

LVL 37

Expert Comment

ID: 38350410
I suppose you would start by getting the last page. Check the number of elements. If it is too much, remove some. If it is not enough, get the next to last page and repeat.
0

Author Comment

ID: 38353131
I have to do ONE request.

I know the number of elements and my page size have 100 elements limit.
0

LVL 37

Expert Comment

ID: 38353972
I don't fully understand the question yet.

"size of the page which can be biiger that 100"
"my page size have 100 elements limit."

So how big can the pages be?

Are you just trying to grab the last X elements from a page? And you know the number of elements on the page? So if there are N elements on the page and you want the last X, you just grab from N-X+1 to N?
0

Author Comment

ID: 38363166
No

I can change the size of the page, but not more that 100.
I can request which page I want and also I can set up the size of the page.

Idea is some matematic formula or something close to .. that tell me. If you want to get last 23 elemets from 111 you have to request the page with number 2 (which I have to calculate) and the size of the page (for all the page from 1 to the last wich is 2 in this case) is 56 elements per page. And you will get 55 elements and you get from that the last 23.

I have to think which is the last page and which is the proper size for a proper request.

Thanks
Petre
0

LVL 37

Expert Comment

ID: 38363414
So there's 56 elements in the first page and 55 in the second and you want the last 23, then N is 55 and X is 23 so you want the pages from N-X+1 to 55 which is 55-23+1 to 55 or 33 to 55?
0

Author Comment

ID: 38366844
no ... this is a simple case ... we have something like this:

case1: get last 44 elements from 745 elements
case2: get last 21 elements from 891 elements
case3: get last 13 elements from 311 elements

all request from one request. So I know the numer of elements and the number of last elementes that I want to get.

there are one solution:  first page and the size of page all elements - not a good solution

but this solution generate a lot of trafic if we get all elements in one page (time out  request, huge trafic .....)

so I have to find a better way to get last elements when I know the number of elements from one request

i can do one request with two parameters:
- which page I want
- which is the general page size

Practical I have to calculate which is the proper page size and the number of pages.

thanks
Petre
0

LVL 37

Expert Comment

ID: 38368269
I still don't really get it. Pages of what? Is this regarding the Internet, or RAM, or what? Is this a programming question? What language?
0

Author Comment

ID: 38371369
Hi,

Any language, I want to find a way to doit. How to calculate the page of size and last page.

Think like this. You have a collection of objects which you have to split in lot of objects (when the lots have the same number of elements), there are situation when last lot is smaller that rest of lots. I need to splet in some way this collection in a way that last lot have more that an number of elements (which i know) and to see how many elements is in a general lot and which is the last lot.

In the real life I have a service which have a function which allow to me to send the page which I want and the size of the page. I have from one request to get the last X elements using that function. What is help me is the fact that I know the total number of elements.

How can I calculate the size of the page and which is the las page? to get the last X elements with best performace. (You can call page 1 with the total number of elements but this is not a proper request)

Thanks
Petre
0

LVL 6

Accepted Solution

yats earned 2000 total points
ID: 38423648
As per you explanation, I think you need to get last X elements which can not be more then 100.

Suppose you need last X elements, which is less then 100.
you have N elements in the table or database.

your question is how to calculate the size of the page:
you can use the below algorithm:
- for i = X to i<=100 {
if(N%i >= X){
then i is the page size
}
}

now page size = i
Page Number = Floor(N/i) + 1

Here % is the modules operation.
Ex: 8%3 = 2 and 17%4 = 1
0

LVL 6

Expert Comment

ID: 38430439
Hope this algo will be helpful. If not please provide what you are missing?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Software development teams often use in-memory caches to improve performance. They want to speed up access to, or reduce load on, a backing store (database, file system, etc.) by keeping some or all of the data in memory. Â  You should implement aâ€¦
Introduction This article discusses the Chain of Responsibility pattern, explaining What it is;Why it is; andHow it is At the end of this article, I hope you will be able to describe the use and benefits of Chain of Responsibility. Â Backgrouâ€¦
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201â€¦
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
###### Suggested Courses
Course of the Month13 days, 7 hours left to enroll