CN103838760B - A kind of method and system inquiring about friend information - Google Patents
A kind of method and system inquiring about friend information Download PDFInfo
- Publication number
- CN103838760B CN103838760B CN201210484514.XA CN201210484514A CN103838760B CN 103838760 B CN103838760 B CN 103838760B CN 201210484514 A CN201210484514 A CN 201210484514A CN 103838760 B CN103838760 B CN 103838760B
- Authority
- CN
- China
- Prior art keywords
- length
- friend
- field
- node
- good friend
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/951—Indexing; Web crawling techniques
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The present invention discloses a kind of method and system inquiring about friend information, and described method includes: store friend information in byte arrays, after having stored a friend information, starts to store another friend information from the next byte storing described friend information;Good friend's node is stored in query node array, good friend's node records good friend uniquely identify and friend information original position in byte arrays, and good friend's node is arranged in query node array by the order uniquely identified from big to small or from small to large by good friend;When receiving field request in inquiry friend information, query node array is inquired about good friend's node, obtains friend information original position in byte arrays;Field is inquired about according to original position and field length.The present invention can solve the problem that storage buddy list takies the problem that memory space is excessive.
Description
Technical field
The present invention relates to computer realm, particularly to a kind of method and system inquiring about friend information.
Background technology
In immediate communication tool, the data of user occupy substantial amounts of memory storage, wrap in the data of user
Containing User Status data and the buddy list of user.Particularly buddy list, online any active ues average
Good friend's number is more than 100, and each user averagely to cache the data of 100 good friends, the packet of good friend
Including: good friend's unique ID, good friend is grouped, and good friend's pet name etc. commonly uses attribute.
In prior art, preserve buddy list by the method for dictionary (Hash table).Wherein, with good friend
Unique ID store as value (Value) as Key (key), the content of friend information.
Use method of the prior art, the user of one 100 good friend of storage at least need to deposit 100 key and
100 good friend's objects.Additionally, also need to cache the object metadata of this good friend for each good friend, right
Object metadata be system be buddy list is operated safeguard operate information data in a large number, such as,
Pointer, the data such as header.This object metadata brings many extra storage overheads, a user
Probably need the internal memory of 22KB.So, cache 3,000,000 online users, then need about 60GB
Internal memory.
Visible, the technical scheme existence storing buddy list in prior art takies excessive the asking of memory space
Topic.
Summary of the invention
The invention provides a kind of method and system inquiring about friend information, account for solution storage buddy list
By the excessive problem of memory space.
The invention discloses a kind of method inquiring about friend information, described method includes:
Friend information is stored in byte arrays, after having stored a friend information, described good from storage
The next byte of friend's information starts to store another friend information;
In query node array, store good friend's node, good friend's node records good friend and uniquely identifies and good friend
Information original position in byte arrays, and uniquely identify from big to small or from small to large by good friend
Good friend's node is arranged in query node array by order;
Wherein, when storing each friend information, by each field in preset order storage friend information,
Preset order includes: first stores each fixed-length field, stores each variable length afterwards,
When storing variable length, first store the length of variable length, store variable length afterwards
The content of degree field;
Described method also includes:
When receiving the request of field in inquiry friend information, unique according to the good friend carried in described request
Mark, inquires about good friend's node of correspondence in query node array, obtains friend information in byte arrays
Original position;
When field to be checked is fixed-length field, according to length, the preset order of fixed-length field
Described field to be checked is obtained with original position;
When field to be checked is variable length, according to length, the variable-length of fixed-length field
The length of field, preset order and original position obtain described field to be checked.
Wherein, described method also includes:
Described when field to be checked is fixed-length field, according to the length of fixed-length field, preset
Order and original position obtain described field to be checked and specifically include:
When described field to be checked is fixed-length field, determine described word to be checked according to preset order
Fixed-length field before Duan, is added the length of each fixed-length field before field to be checked
Drawing the side-play amount of field to be checked, from original position, the position after side-play amount byte is word to be checked
The original position of section;
Described when field to be checked is variable length, according to the length of fixed-length field, variable
The length of length field, preset order and original position obtain described field to be checked and specifically include:
When described field to be checked is variable length, according to original position and all fixed length words
The length of section draws the original position of first variable length, draws word to be checked according to preset order
The serial number of section, from the beginning of the original position of first variable length, reads variable length
Length, is jumped to the original position of next variable length by described length, until true according to serial number
Surely till jumping to the original position of field to be checked.
Wherein, described method also includes:
When deleting friend information, from query node array, delete good friend's node of correspondence, and will delete
Good friend's node after good friend's node move forward successively in query node array, and will delete good friend joint
Point is put in deletion of node array.
Wherein, described method also includes:
When inserting friend information, generate good friend's node of described friend information, according to good in good friend's node
The unique mark of friend determines this good friend's node position in query node array, described in good friend's node city
Position;
By the field in preset order arrangement friend information, adding this before the content of variable length can
Become the length of length field, to complete the operation of the serializing to friend information;
Inquiry deletion of node array, it may be judged whether there is the friend information total length of correspondence not less than described sequence
Good friend's node of the friend information total length after rowization;
If it is present exist with the good friend's node inquired described in the friend information replacement after described serializing
Record storage in friend information in byte arrays, and good friend's node of the insertion in query node array
The original position of the friend information of described insertion, the good friend's node being replaced by friend information is from deletion of node
Array is deleted;
If it does not exist, then start the friend information after storing described serializing from the ending of byte arrays,
In good friend's node at the friend information place inserted, record stores the initial of the friend information of described insertion
Position.
Wherein, when revising friend information, from byte arrays, the word of friend information to be modified is inquired
Section;
When field to be modified is fixed-length field, directly revise the field inquired;
When field to be modified is variable length, read described field from the field header inquired
Length, it is judged that amended field length whether more than the length of the described field read, if it is not,
Then directly revise the field inquired;
If it is, proceed as follows:
Inquiry deletion of node array, it may be judged whether exist correspondence friend information total length not less than amendment after
Good friend's node of friend information total length;
If it does, with the good friend's node inquired described in the replacement of described amended friend information in byte
Friend information in array, and the good friend's node being replaced by friend information deletes from deletion of node array
Remove;
If it does not exist, then start to store described amended friend information from the ending of byte arrays;
After completing amendment, friend information to be modified good friend's node in query node array is replicated,
Good friend's node of duplication is put in deletion of node array, and the described good friend in query node array is saved
The original position of amended friend information is stored during original position is updated to byte arrays in point.
Wherein, the described good friend's node inquiring about correspondence in query node array includes:
In query node array, good friend's node of correspondence is inquired about by two way classification.
The invention also discloses a kind of system inquiring about friend information, described system includes:
Information storage module, for storing friend information, when having stored good friend's letter in byte arrays
After breath, start to store another friend information from the next byte storing described friend information,
Wherein, when storing each friend information, for by each word in preset order storage friend information
Section, preset order includes: first stores each fixed-length field, stores each variable length afterwards,
When storing variable length, being used for first storing the length of variable length, storage can afterwards
Become the content of length field;
Index memory module, for storing good friend's node, record in good friend's node in query node array
Good friend uniquely identifies and friend information original position in byte arrays, and uniquely identify by good friend from
To order little or from small to large, good friend's node is arranged in query node array greatly;
Enquiry module, during for receiving the request of field in inquiry friend information, according in described request
The good friend carried uniquely identifies, and inquires about good friend's node of correspondence in query node array, obtains good friend's letter
Breath original position in byte arrays;When field to be checked is fixed-length field, according to fixing length
The degree length of field, preset order and original position obtain described field to be checked;In field to be checked it is
During variable length, according to the length of fixed-length field, the length of variable length, preset suitable
Sequence and original position obtain described field to be checked.
Wherein, described enquiry module, specifically for when field to be checked is fixed-length field, according to
Preset order determines the fixed-length field before described field to be checked, each by before field to be checked
The length of individual fixed-length field is added the side-play amount drawing field to be checked, side-play amount from original position
Position after individual byte is the original position of field to be checked;
When field to be checked is variable length, according to original position and all fixed-length fields
Length draws the original position of first variable length, draws field to be checked according to preset order
Serial number, from the beginning of the original position of first variable length, reads the length of variable length,
The original position of next variable length is jumped to, until determining according to serial number and jumping to by described length
Till the original position of field to be checked.
Wherein, described system also includes:
Removing module, for when deleting friend information, deletes the good friend of correspondence from query node array
Node, and the good friend's node after good friend's node of deletion is moved forward in query node array successively, and
Good friend's node of deletion is put in deletion of node array.
Wherein, described system also includes:
Insert module, for when inserting friend information, generating good friend's node of described friend information, root
Uniquely identify according to good friend in good friend's node and determine this good friend's node position in query node array, incite somebody to action
Position described in friend's node city;
By the field in preset order arrangement friend information, adding this before the content of variable length can
Become the length of length field, to complete the operation of the serializing to friend information;
Inquiry deletion of node array, it may be judged whether there is the friend information total length of correspondence not less than described sequence
Good friend's node of the friend information total length after rowization;
If it is present exist with the good friend's node inquired described in the friend information replacement after described serializing
Record storage in friend information in byte arrays, and good friend's node of the insertion in query node array
The original position of the friend information of described insertion, the good friend's node being replaced by friend information is from deletion of node
Array is deleted;
If it does not exist, then start the friend information after storing described serializing from the ending of byte arrays,
In good friend's node at the friend information place inserted, record stores the initial of the friend information of described insertion
Position.
The invention has the beneficial effects as follows: in the present invention in byte arrays Coutinuous store friend information, depositing
During storage friend information, first store each fixed-length field, then store each variable length, depositing
During storage variable length, first store the length of variable length, store variable length afterwards
Content, and in query node array, storage record good friend uniquely identifies with friend information in byte arrays
In good friend's node of original position, and uniquely identify order from big to small or from small to large by good friend
Good friend's node is arranged in query node array;Visible, by Coutinuous store friend information, and deposit
The length of storage variable length, can either realize storing operation normally, again it can be avoided that use object
Metadata, saves out by the space being used for storing object metadata, and then saves storage overhead, and
And uniquely identified and original position by individually storage good friend, and foundation good friend uniquely identifies and is ranked up,
Quick-searching can be carried out, improve the operating efficiency to buddy list.
Accompanying drawing explanation
Fig. 1 is the flow chart of the method inquiring about friend information in one embodiment of the invention.
Fig. 2 is the structural representation of friend information in buddy list in one embodiment of the invention.
Fig. 3 is to inquire about the flow process of the method for the field of friend information in buddy list in one embodiment of the invention
Figure.
Fig. 4 is the flow chart of the method inserting friend information in one embodiment of the invention in buddy list.
Fig. 5 is the flow chart of the method revising friend information in one embodiment of the invention in buddy list.
Fig. 6 is the structure chart of the system inquiring about friend information in one embodiment of the invention.
Detailed description of the invention
For making the object, technical solutions and advantages of the present invention clearer, below in conjunction with accompanying drawing to this
Bright embodiment is described in further detail.
See Fig. 1, for the flow chart of the method inquiring about friend information a kind of in one embodiment of the invention.Its
In, comprise the steps.
Step S100, stores friend information in byte arrays, after having stored a friend information, from
The next byte storing described friend information starts to store another friend information.
Wherein, when storing each friend information, by each field in preset order storage friend information,
Preset order includes: first stores each fixed-length field, stores each variable length afterwards;?
During storage variable length, first store the length of variable length, store variable length afterwards
Content.
Step S200, stores good friend's node in query node array, records good friend unique in good friend's node
Mark and friend information original position in byte arrays, and uniquely identify from big to small by good friend or
Good friend's node is arranged in query node array by order from small to large.
Step S300, when receiving the request of field in inquiry friend information, carries according in described request
Good friend uniquely identify, inquire about in query node array correspondence good friend's node, obtain friend information exist
Original position in byte arrays;When field to be checked is fixed-length field, according to fixed length word
Length, preset order and the original position of section obtain described field to be checked;It is variable in field to be checked
During length field, according to the length of fixed-length field, the length of variable length, preset order and
Original position obtains described field to be checked.
Illustrative to the present embodiment below.
When storing friend information, each friend information is serialized.Field in friend information is pressed
After first fixed-length field, the order of variable length arranges, and in variable length word g. slice header
Add the length of field.Further, for the buddy list of each user, wherein each good friend's is good
The field that friend's information includes, i.e. item of information, identical, putting in order of those fields is identical, and by advance
If order regulation.Such as, the schematic diagram of the arrangement of the field in friend information is as shown in Figure 2.Wherein,
Friend information includes: m fixed-length field and n variable length.Fixed-length field is i.e.
For the field of those regular length types, such as numeric type (integer type, lint-long integer type, short integer type),
Date type etc..Variable-length type is the field of the unfixed type of those length, such as character string type.
For the friend information in quick-searching to above-mentioned byte arrays, set up an index, i.e. inquire about joint
Point array, in order to record the original position of storage friend information.After obtaining original position, just can join
According to preset order, the such as order shown in Fig. 2, read the field in friend information or good friend is believed
Field in breath does the operations such as assignment.
In the present embodiment, by Coutinuous store friend information, and store the length of variable length,
Can either realize storing operation normally, again it can be avoided that use object metadata, will be used for storing object
The space of metadata is saved out, and then saves storage overhead, and unique by individually storage good friend
Identify and original position, and foundation good friend uniquely identifies and is ranked up, it is possible to carry out quick-searching, improve
Operating efficiency to buddy list.
In one embodiment, inquiry friend information method includes: look in query node array by two way classification
Ask good friend's node, obtain friend information original position in byte arrays;For fixed-length field,
Starting reading out fixed-length field friend information from original position, for variable length, reading can
Become length in length field, take out variable length by described length read.
See Fig. 3, for one embodiment of the invention is inquired about certain field in the friend information of buddy list
The flow chart of method.Described method also comprises the steps.
Step S310 is when receiving the request of field in inquiry friend information, good according to carry in request
The unique mark of friend, inquires about good friend's node of correspondence in query node array, obtains friend information in byte
Original position in array.Further, when query node array is inquired about, can be with two points
Method is inquired about.
Step S320, it is judged that whether field to be checked is fixed-length field, if it is, perform step
S330, otherwise, performs step S340.Wherein, field to be checked is to be inquired about good of described request
Field in friend's information.
Step S330, when field to be checked is fixed-length field, determines to be checked according to preset order
Fixed-length field before field, by the length phase of each fixed-length field before field to be checked
Adding the side-play amount drawing field to be checked, from original position, the position after side-play amount byte is to be checked
The original position of field.
Herein, illustrative to step S330.Inquiry can be known to from preset order
The sequence number of fixed-length field, for example, kth fixed-length field, then will before the 1st to the
The length of k-1 fixed-length field is added the side-play amount drawing this kth fixed-length field.From
Position after side-play amount byte is played in beginning position starts as field to be inquired about.
Step S340, when field to be checked is variable length, according to original position and all fixing
The length of length field draws the original position of first variable length, draws according to preset order and treats
The serial number of inquiry field, from the beginning of the original position of first variable length, reads variable-length
The length of field, is jumped to the original position of next variable length by described length, until according to suitable
Till sequence number determines the original position jumping to field to be checked.
Herein, illustrative to step S340.Such as, i-th variable-length in query graph 2
Field.The length of all fixed-length fields is added the side-play amount drawing first variable length,
Position after this side-play amount byte reads from original position the length of first variable length,
The original position of second variable length is jumped to by the length read, so on.When skipping i-1
After individual variable length, jump to the original position of variable-length byte to be inquired about, thereby determine that
The original position of i variable length, inquires i-th variable length.
In the present embodiment, owing to using query node array to be uniquely designated index to friend information
Original position carries out record, wherein, uniquely mark is sorted by size, it is thus possible to utilize two way classification pair
Query node array is inquired about, such that it is able to the original position of quick obtaining friend information.Such as, good
Friend's list comprises good friend's data of more than 100, if with linear way of search, time complexity
It is 100, and the time complexity of two way classification is log2100, i.e. 6 to 7 times.Visible, use this reality
Executing middle method, inquiry velocity significantly improves.
In one embodiment, when deleting friend information, from query node array, delete the good friend of correspondence
Node, and the good friend's node after good friend's node of deletion is moved forward in query node array successively, and
Good friend's node of deletion is put in deletion of node array.
When using the mode of above-mentioned deletion friend information, friend information can be inserted in the following way.
See Fig. 4, for one embodiment of the invention is inserted in buddy list the flow chart of the method for friend information.
Described method comprises the steps.
Step S410, when inserting friend information, generates good friend's node of the friend information inserted, according to
In good friend's node, good friend uniquely identifies and determines this good friend's node position in query node array, by good friend
This position of node city.
Illustrative to step S410.Generating good friend's node, in good friend's node, ID is preferably
The unique mark of friend;Search whether it exists this good friend joint in query node array by two way classification according to ID
Point.Insert, if it is present return, the mistake repeated, i.e. the buddy list of user can not have two
Identical good friend.If it does not exist, then return this good friend's node on position in query node array,
It is expressed as insertindex.In this example, ID puts in order as from small to large.So the good friend's joint inserted
The ID of point is less than the ID of good friend's node corresponding for insertindex, and is more than insertindex-1 (if depositing
) ID of corresponding good friend's node.Insertindex and all good friend's node entirety afterwards are moved back by
A dynamic position, then by good friend's node city of being inserted into original insertindex position.
Step S420, by the field in preset order arrangement friend information, in the content of variable length
The length of front this variable length of interpolation, to complete the operation of the serializing to friend information.
When deletion of node array is empty when initial, directly perform step S470.Byte arrays is inserted
The original position of friend's information, is expressed as blobInsertIndex, blobInsertIndex and is initially 0, every time
When inserting a new friend information, by friend information from blobInsertIndex position entirety assignment to byte
In array, then blobInsertIndex plus the length of friend information, insert friend information the most every time,
Directly copy friend information from end position entirety.
Step S430, inquires about deletion of node array, it may be judged whether there is the friend information total length of correspondence not
Less than good friend's node of the friend information total length after described serializing, if it does, perform step
S440, if it does not, perform step S470.
Step S440, deletes friend information corresponding for the good friend's node inquired from byte arrays and obtains
Null byte, is stored in the friend information after serializing in null byte.
Step S450, record storage in the friend information inserted good friend's node in query node array
The original position of the friend information inserted.
Step S460, has been inserted into good friend's node of friend information replacement from deletion of node by friend information
Array is deleted.
Step S470, starts the friend information after storing described serializing from the ending of byte arrays, is inserting
The original position of the friend information that record storage is inserted in good friend's node at the friend information place entered.
By this insertion method, it is possible to effectively utilize deleted friend information space in byte arrays,
Avoid the waste of memory space.
See Fig. 5, for one embodiment of the invention is revised in buddy list the stream of the method for friend information
Cheng Tu.
Step S510, inquires the field of friend information to be modified from byte arrays.
Herein, the method for field in aforesaid query modification friend information is used.
Step S520, it is judged that whether the field of amendment is fixed-length field, if it is, perform step
S530, otherwise, performs step S540.
Step S530, directly revises the field inquired.
Step S540, when field to be modified is variable length, reads from the field header inquired
Go out the length of this field, it is judged that the length that amended field length is the most present more than this field read
Degree, if it is not, then perform step S530, if it is, perform step S550.
Step S550, inquires about deletion of node array, it may be judged whether there is the friend information total length of correspondence not
Less than good friend's node of amended friend information total length, if it does, perform step S560, no
Then, step S570 is performed.
Step S560, with the good friend's node inquired described in the replacement of amended friend information in byte arrays
In friend information, and the good friend's node being replaced by friend information deletes from deletion of node array.
Step S570, starts to store described amended friend information from the ending of byte arrays.
Step S580, after completing amendment, by friend information to be modified good friend in query node array
Node replicates, and is put in deletion of node array by good friend's node of duplication.
Step S590, will rise in good friend's node corresponding for the friend information to be modified in query node array
Beginning location updating is the original position storing amended friend information in byte arrays.
By this amending method, it is possible to effectively utilize deleted friend information space in byte arrays,
Avoid the waste of memory space.
See the structure chart that Fig. 6 is the system inquiring about friend information in one embodiment of the invention.
Information storage module 610 is for storing friend information in byte arrays, good when having stored one
After friend's information, start to store another friend information from the next byte storing described friend information.
Wherein, when storing each friend information, for by each word in preset order storage friend information
Section, preset order includes: first stores each fixed-length field, stores each variable length afterwards,
When storing variable length, being used for first storing the length of variable length, storage can afterwards
Become the content of length field;
Index memory module 620, for storing good friend's node, in good friend's node in query node array
Record good friend uniquely identifies and friend information original position in byte arrays, and uniquely marks by good friend
Know order from big to small or from small to large to be arranged in query node array by good friend's node.
Described system also includes enquiry module 630, for receiving the request of field in inquiry friend information
Time, uniquely identify according to the good friend carried in described request, query node array is inquired about the good of correspondence
Friend's node, obtains friend information original position in byte arrays;It is regular length in field to be checked
During field, obtain described word to be checked according to length, preset order and the original position of fixed-length field
Section;When field to be checked is variable length, according to length, the variable-length of fixed-length field
The length of field, preset order and original position obtain described field to be checked.
In the present embodiment, by Coutinuous store friend information, and store the length of variable length,
Can either realize storing operation normally, again it can be avoided that use object metadata, will be used for storing object
The space of metadata is saved out, and then saves storage overhead, and unique by individually storage good friend
Identify and original position, and foundation good friend uniquely identifies and is ranked up, it is possible to carry out quick-searching, improve
Operating efficiency to buddy list.
In one embodiment, enquiry module 630, specifically for being fixed-length field in field to be checked
Time, determine the fixed-length field before described field to be checked according to preset order, by field to be checked
The length of each fixed-length field before is added the side-play amount drawing field to be checked, from original position
Play the original position that position is field to be checked after side-play amount byte;
When field to be checked is variable length, according to original position and all fixed-length fields
Length draws the original position of first variable length, draws field to be checked according to preset order
Serial number, from the beginning of the original position of first variable length, reads the length of variable length,
The original position of next variable length is jumped to, until determining according to serial number and jumping to by described length
Till the original position of field to be checked.
Further, described enquiry module 630 specifically for: in query node array, inquiry is corresponding
During good friend's node, in query node array, inquire about good friend's node of correspondence by two way classification.
In the present embodiment, owing to using query node array to be uniquely designated index to friend information
Original position carries out record, wherein, uniquely mark is sorted by size, it is thus possible to utilize two way classification pair
Query node array is inquired about, such that it is able to the original position of quick obtaining friend information.Such as, good
Friend's list comprises good friend's data of more than 100, if with linear way of search, time complexity
It is 100, and the time complexity of two way classification is log2100, i.e. 6 to 7 times.Visible, use this reality
Executing middle method, inquiry velocity significantly improves.
In one embodiment, described system also includes:
Removing module, for when deleting friend information, deletes the good friend of correspondence from query node array
Node, and the good friend's node after good friend's node of deletion is moved forward in query node array successively, and
Good friend's node of deletion is put in deletion of node array.
Further, described system also includes:
Insert module, for when inserting friend information, generating good friend's node of described friend information, root
Uniquely identify according to good friend in good friend's node and determine this good friend's node position in query node array, incite somebody to action
Position described in friend's node city;
By the field in preset order arrangement friend information, adding this before the content of variable length can
Become the length of length field, to complete the operation of the serializing to friend information;
Inquiry deletion of node array, it may be judged whether there is the friend information total length of correspondence not less than described sequence
Good friend's node of the friend information total length after rowization;
If it is present exist with the good friend's node inquired described in the friend information replacement after described serializing
Record storage in friend information in byte arrays, and good friend's node of the insertion in query node array
The original position of the friend information of described insertion, the good friend's node being replaced by friend information is from deletion of node
Array is deleted;
If it does not exist, then start the friend information after storing described serializing from the ending of byte arrays,
The original position of the friend information that record storage is inserted in the friend information place good friend's node inserted.
Inserted by which, it is possible to effectively utilize deleted friend information space in byte arrays,
Avoid the waste of memory space.
Further, described system also includes:
Modified module, for when revising friend information, inquiring good friend to be modified from byte arrays
The field of information;
When field to be modified is fixed-length field, directly revise the field inquired;
When field to be modified is variable length, read described field from the field header inquired
Length, it is judged that amended field length whether more than the length of the described field read, if it is not,
Then directly revise the field inquired;
If it is, proceed as follows:
Inquiry deletion of node array, it may be judged whether exist correspondence friend information total length not less than amendment after
Good friend's node of friend information total length;
If it does, with the good friend's node inquired described in the replacement of described amended friend information in byte
Friend information in array, and the good friend's node being replaced by friend information deletes from deletion of node array
Remove;
If it does not exist, then start to store described amended friend information from the ending of byte arrays;
After completing amendment, friend information to be modified good friend's node in query node array is replicated,
Good friend's node of duplication is put in deletion of node array, and the described good friend in query node array is saved
The original position of amended friend information is stored during original position is updated to byte arrays in point.
Pass-through mode is modified, it is possible to effectively utilize deleted friend information sky in byte arrays
Between, it is to avoid the waste of memory space.
The foregoing is only presently preferred embodiments of the present invention, be not intended to limit the protection model of the present invention
Enclose.All any modification, equivalent substitution and improvement etc. made within the spirit and principles in the present invention, all
Comprise within the scope of the present invention.
Claims (10)
1. the method inquiring about friend information, it is characterised in that described method includes:
Friend information is stored in byte arrays, after having stored a friend information, described good from storage
The next byte of friend's information starts to store another friend information;
In query node array, store good friend's node, good friend's node records good friend and uniquely identifies and good friend
Information original position in byte arrays, and uniquely identify from big to small or from small to large by good friend
Good friend's node is arranged in query node array by order;
Wherein, when storing each friend information, by each field in preset order storage friend information,
Preset order includes: first stores each fixed-length field, stores each variable length afterwards,
When storing variable length, first store the length of variable length, store variable length afterwards
The content of degree field;
Described method also includes:
When receiving the request of field in inquiry friend information, unique according to the good friend carried in described request
Mark, inquires about good friend's node of correspondence in query node array, obtains friend information in byte arrays
Original position;
When field to be checked is fixed-length field, according to length, the preset order of fixed-length field
Described field to be checked is obtained with original position;
When field to be checked is variable length, according to length, the variable-length of fixed-length field
The length of field, preset order and original position obtain described field to be checked.
Method the most according to claim 1, it is characterised in that
Described when field to be checked is fixed-length field, according to the length of fixed-length field, preset
Order and original position obtain described field to be checked and specifically include:
When described field to be checked is fixed-length field, determine described word to be checked according to preset order
Fixed-length field before Duan, is added the length of each fixed-length field before field to be checked
Drawing the side-play amount of field to be checked, from original position, the position after side-play amount byte is word to be checked
The original position of section;
Described when field to be checked is variable length, according to the length of fixed-length field, variable
The length of length field, preset order and original position obtain described field to be checked and specifically include:
When described field to be checked is variable length, according to original position and all fixed length words
The length of section draws the original position of first variable length, draws word to be checked according to preset order
The serial number of section, from the beginning of the original position of first variable length, reads variable length
Length, is jumped to the original position of next variable length by described length, until true according to serial number
Surely till jumping to the original position of field to be checked.
Method the most according to claim 2, it is characterised in that
Described method also includes:
When deleting friend information, from query node array, delete good friend's node of correspondence, and will delete
Good friend's node after good friend's node move forward successively in query node array, and will delete good friend joint
Point is put in deletion of node array.
Method the most according to claim 3, it is characterised in that
Described method also includes:
When inserting friend information, generate good friend's node of described friend information, according to good in good friend's node
The unique mark of friend determines this good friend's node position in query node array, described in good friend's node city
Position;
By the field in preset order arrangement friend information, adding this before the content of variable length can
Become the length of length field, to complete the operation of the serializing to friend information;
Inquiry deletion of node array, it may be judged whether there is the friend information total length of correspondence not less than described sequence
Good friend's node of the friend information total length after rowization;
If it is present exist with the good friend's node inquired described in the friend information replacement after described serializing
Record storage in friend information in byte arrays, and good friend's node of the insertion in query node array
The original position of the friend information of described insertion, the good friend's node being replaced by friend information is from deletion of node
Array is deleted;
If it does not exist, then start the friend information after storing described serializing from the ending of byte arrays,
In good friend's node at the friend information place inserted, record stores the initial of the friend information of described insertion
Position.
Method the most according to claim 3, it is characterised in that
When revising friend information, from byte arrays, inquire the field of friend information to be modified;
When field to be modified is fixed-length field, directly revise the field inquired;
When field to be modified is variable length, read described field from the field header inquired
Length, it is judged that amended field length whether more than the length of the described field read, if it is not,
Then directly revise the field inquired;
If it is, proceed as follows:
Inquiry deletion of node array, it may be judged whether exist correspondence friend information total length not less than amendment after
Good friend's node of friend information total length;
If it does, with the good friend's node inquired described in the replacement of described amended friend information in byte
Friend information in array, and the good friend's node being replaced by friend information deletes from deletion of node array
Remove;
If it does not exist, then start to store described amended friend information from the ending of byte arrays;
After completing amendment, friend information to be modified good friend's node in query node array is replicated,
Good friend's node of duplication is put in deletion of node array, and the described good friend in query node array is saved
The original position of amended friend information is stored during original position is updated to byte arrays in point.
Method the most according to claim 1, it is characterised in that
The described good friend's node inquiring about correspondence in query node array includes:
In query node array, good friend's node of correspondence is inquired about by two way classification.
7. the system inquiring about friend information, it is characterised in that described system includes:
Information storage module, for storing friend information, when having stored good friend's letter in byte arrays
After breath, start to store another friend information from the next byte storing described friend information,
Wherein, when storing each friend information, for by each word in preset order storage friend information
Section, preset order includes: first stores each fixed-length field, stores each variable length afterwards,
When storing variable length, being used for first storing the length of variable length, storage can afterwards
Become the content of length field;
Index memory module, for storing good friend's node, record in good friend's node in query node array
Good friend uniquely identifies and friend information original position in byte arrays, and uniquely identify by good friend from
To order little or from small to large, good friend's node is arranged in query node array greatly;
Enquiry module, during for receiving the request of field in inquiry friend information, according in described request
The good friend carried uniquely identifies, and inquires about good friend's node of correspondence in query node array, obtains good friend's letter
Breath original position in byte arrays;When field to be checked is fixed-length field, according to fixing length
The degree length of field, preset order and original position obtain described field to be checked;In field to be checked it is
During variable length, according to the length of fixed-length field, the length of variable length, preset suitable
Sequence and original position obtain described field to be checked.
System the most according to claim 7, it is characterised in that
Described enquiry module, specifically for when field to be checked is fixed-length field, suitable according to presetting
Sequence determines the fixed-length field before described field to be checked, is fixed by each before field to be checked
The length of length field is added the side-play amount drawing field to be checked, side-play amount byte from original position
After the original position that position is field to be checked;
When field to be checked is variable length, according to original position and all fixed-length fields
Length draws the original position of first variable length, draws field to be checked according to preset order
Serial number, from the beginning of the original position of first variable length, reads the length of variable length,
The original position of next variable length is jumped to, until determining according to serial number and jumping to by described length
Till the original position of field to be checked.
System the most according to claim 7, it is characterised in that
Described system also includes:
Removing module, for when deleting friend information, deletes the good friend of correspondence from query node array
Node, and the good friend's node after good friend's node of deletion is moved forward in query node array successively, and
Good friend's node of deletion is put in deletion of node array.
System the most according to claim 9, it is characterised in that
Described system also includes:
Insert module, for when inserting friend information, generating good friend's node of described friend information, root
Uniquely identify according to good friend in good friend's node and determine this good friend's node position in query node array, incite somebody to action
Position described in friend's node city;
By the field in preset order arrangement friend information, adding this before the content of variable length can
Become the length of length field, to complete the operation of the serializing to friend information;
Inquiry deletion of node array, it may be judged whether there is the friend information total length of correspondence not less than described sequence
Good friend's node of the friend information total length after rowization;
If it is present exist with the good friend's node inquired described in the friend information replacement after described serializing
Record storage in friend information in byte arrays, and good friend's node of the insertion in query node array
The original position of the friend information of described insertion, the good friend's node being replaced by friend information is from deletion of node
Array is deleted;
If it does not exist, then start the friend information after storing described serializing from the ending of byte arrays,
In good friend's node at the friend information place inserted, record stores the initial of the friend information of described insertion
Position.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210484514.XA CN103838760B (en) | 2012-11-23 | 2012-11-23 | A kind of method and system inquiring about friend information |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210484514.XA CN103838760B (en) | 2012-11-23 | 2012-11-23 | A kind of method and system inquiring about friend information |
Publications (2)
Publication Number | Publication Date |
---|---|
CN103838760A CN103838760A (en) | 2014-06-04 |
CN103838760B true CN103838760B (en) | 2016-12-21 |
Family
ID=50802271
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201210484514.XA Active CN103838760B (en) | 2012-11-23 | 2012-11-23 | A kind of method and system inquiring about friend information |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103838760B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110019336B (en) * | 2017-10-30 | 2021-04-30 | 北京京东尚科信息技术有限公司 | Method and device for querying data |
CN110990407B (en) * | 2018-04-27 | 2020-11-10 | 腾讯科技(深圳)有限公司 | Block chain based data storage method and device, server and storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101119214B (en) * | 2007-07-13 | 2010-06-09 | 腾讯科技(深圳)有限公司 | Processing method of displaying service mark in instant communication instrument |
CN101299769B (en) * | 2008-05-14 | 2011-01-26 | 天津华永无线科技有限公司 | Construction method of micro blog system based on geographical position |
CN101968818A (en) * | 2010-11-08 | 2011-02-09 | 北京开心人信息技术有限公司 | Method and system for recommending fiends to user in social network site |
CN102111343A (en) * | 2009-12-28 | 2011-06-29 | 中兴通讯股份有限公司 | Method for implementing instant messaging control and system adopting same |
-
2012
- 2012-11-23 CN CN201210484514.XA patent/CN103838760B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101119214B (en) * | 2007-07-13 | 2010-06-09 | 腾讯科技(深圳)有限公司 | Processing method of displaying service mark in instant communication instrument |
CN101299769B (en) * | 2008-05-14 | 2011-01-26 | 天津华永无线科技有限公司 | Construction method of micro blog system based on geographical position |
CN102111343A (en) * | 2009-12-28 | 2011-06-29 | 中兴通讯股份有限公司 | Method for implementing instant messaging control and system adopting same |
CN101968818A (en) * | 2010-11-08 | 2011-02-09 | 北京开心人信息技术有限公司 | Method and system for recommending fiends to user in social network site |
Also Published As
Publication number | Publication date |
---|---|
CN103838760A (en) | 2014-06-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105320775B (en) | The access method and device of data | |
KR101122887B1 (en) | Efficient capitalization through user modeling | |
US7467155B2 (en) | Method and apparatus for representation of unstructured data | |
CN111190904B (en) | Method and device for hybrid storage of graph-relational database | |
CN101641695B (en) | Resource access filtering system and database structure for use therewith | |
CN103810224B (en) | information persistence and query method and device | |
US7526497B2 (en) | Database retrieval apparatus, retrieval method, storage medium, and program | |
CN108460041B (en) | Data processing method and device | |
CN103365992B (en) | Method for realizing dictionary search of Trie tree based on one-dimensional linear space | |
JP2007500408A (en) | Database query user interface | |
CN102016789A (en) | Data processing apparatus and method of processing data | |
CN101727502A (en) | Data query method, data query device and data query system | |
WO2008053583A1 (en) | Bit sequence searching method and program | |
JP5558514B2 (en) | Method and apparatus for optimally processing N-sort queries in multi-range scanning | |
WO2015010508A1 (en) | One-dimensional linear space-based method for implementing trie tree dictionary storage and management | |
CN107239549A (en) | Method, device and the terminal of database terminology retrieval | |
CN106528647A (en) | Term matching method based on a cedar double-array trie algorithm | |
CN105912696A (en) | DNS (Domain Name System) index creating method and query method based on logarithm merging | |
CN103838760B (en) | A kind of method and system inquiring about friend information | |
CN111324483B (en) | Data recovery method and device and related equipment | |
CN101635001B (en) | Method and apparatus for extracting information from a database | |
KR101358793B1 (en) | Method of forming index file, Method of searching data and System for managing data using dictionary index file, Recoding medium | |
CN109325022B (en) | Data processing method and device | |
CN110825747B (en) | Information access method, device and medium | |
US8166043B2 (en) | Bit strings search apparatus, search method, and program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
CP02 | Change in the address of a patent holder |
Address after: Room 818, 8 / F, 34 Haidian Street, Haidian District, Beijing 100080 Patentee after: BEIJING ULTRAPOWER SOFTWARE Co.,Ltd. Address before: 100089 Beijing city Haidian District wanquanzhuang Road No. 28 Wanliu new building 6 storey block A Room 601 Patentee before: BEIJING ULTRAPOWER SOFTWARE Co.,Ltd. |
|
CP02 | Change in the address of a patent holder |